Php-amqplib: Undefined constant SOCKET_EAGAIN in Windows

Created on 15 Nov 2018  Â·  5Comments  Â·  Source: php-amqplib/php-amqplib

I have found a compatibility bug at \PhpAmqpLib\Wire\IO\StreamIO.php line 88:

self::$ERRNO_EQUALS_EAGAIN = 'errno=' . SOCKET_EAGAIN;

I checked the PHP source code, the SOCKET_EAGAIN constant is referred from EAGAIN, but cannot be accessed in Windows (EWOULDBLOCK instead in Windows). Thus the program would crash due to this undefined constant. Please kindly check whether defined SOCKET_EAGAIN before use it, or replace it by SOCKET_EWOULDBLOCK, also it's an alias for SOCKET_EAGAIN in Linux.

// patch type1:
self::$ERRNO_EQUALS_EAGAIN = 'errno=' . (defined('SOCKET_EAGAIN') ? SOCKET_EAGAIN : SOCKET_EWOULDBLOCK);

// patch type2:
self::$ERRNO_EQUALS_EAGAIN = 'errno=' . SOCKET_EWOULDBLOCK;

Most helpful comment

from your php.ini uncomment this

;extension=php_sockets.dll

P.S if you are using docker install the extension on your Dockerfile

RUN docker-php-ext-install sockets

All 5 comments

If you have time, a pull request would be appreciated. Thanks!

When I hardcode the value for this, it is working for me

        self::$ERRNO_EQUALS_EAGAIN = 'errno=' . SOCKET_EAGAIN;
        self::$ERRNO_EQUALS_EWOULDBLOCK = 'errno=' . SOCKET_EWOULDBLOCK;
        self::$ERRNO_EQUALS_EINTR = 'errno=' . SOCKET_EINTR;

I fixed this issue by enabling the socket ext in php

@nifrasismail
How did you enable socket ext ?

from your php.ini uncomment this

;extension=php_sockets.dll

P.S if you are using docker install the extension on your Dockerfile

RUN docker-php-ext-install sockets
Was this page helpful?
0 / 5 - 0 ratings

Related issues

nubeiro picture nubeiro  Â·  6Comments

henriqueoliveira picture henriqueoliveira  Â·  10Comments

d3xt3r01 picture d3xt3r01  Â·  8Comments

kozlice picture kozlice  Â·  4Comments

r-simlinger picture r-simlinger  Â·  5Comments