ERRoR : Expected a valid PHP stream resource

Issue #37 closed
Former user created an issue

Hello, can you help me see I don't know why, tcp should be the correct resource, but it gives an error code:

<?php
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($sock, '127.0.0.1', '12346');
socket_listen($sock);
socket_set_nonblock($sock);
var_dump($sock);

$w = new EvIo($sock, Ev::READ, function ($w) use ($sock) { var_dump($w); });

Ev::run();

output:

resource(4) of type (Socket)
PHP Fatal error: Uncaught Exception: Expected a valid PHP stream resource in /demo.php:10
Stack trace:
#0/demo.php(10): EvIo->__construct(Resource id #4, 1, Object(Closure))
#1 {main} thrown in /demo.php on line 10

Comments (4)

  1. Murray Cai

    It is not useful , EvTimercan use this $sock, but EvIo give the same error! My php’s code is the example 2. error at

    $write_watcher = new EvIo($socket, Ev::WRITE, function ($w){});
    

    this is my php-config, what is wrong?

    [root@192 php-7.4.18]# php-config
    Usage: /usr/local/bin/php-config [OPTION]
    Options:
      --prefix            [/root/php/bin/php74]
      --includes          [-I/root/php/bin/php74/include/php -I/root/php/bin/php74/include/php/main -I/root/php/bin/php74/include/php/TSRM -I/root/php/bin/php74/include/php/Zend -I/root/php/bin/php74/include/php/ext -I/root/php/bin/php74/include/php/ext/date/lib]
      --ldflags           []
      --libs              [-lcrypt   -lresolv -lcrypt -lrt -lrt -lm -ldl  -lxml2 -lsqlite3 -lxml2 -lsqlite3 -lxml2 -lcrypt -lxml2 -lxml2 -lxml2 -lz -lcrypt ]
      --extension-dir     [/root/php/bin/php74/lib/php/extensions/debug-non-zts-20190902]
      --include-dir       [/root/php/bin/php74/include/php]
      --man-dir           [/root/php/bin/php74/php/man]
      --php-binary        [/root/php/bin/php74/bin/php]
      --php-sapis         [ cli fpm phpdbg cgi]
      --ini-path          [/root/php/bin/php74/lib]
      --ini-dir           []
      --configure-options [--prefix=/root/php/bin/php74 --enable-debug --enable-fpm --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd PKG_CONFIG_LIBDIR=/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig --enable-sockets]
      --version           [7.4.18]
      --vernum            [70418]
    

  2. Ruslan Osmanov repo owner

    @Murray Cai ,

    It is not useful , EvTimercan use this $sock, but EvIo give the same error!

    Sorry, but I can only deal with the information provided in this bug report. If there was a docker image demonstrating the problem, it would be easier for me to track down the exact configuration issue you have there.

    EvTimer doesn’t accept any socket or stream resources so I can’t see how it could possibly use it except for passing it to the callback, but this is a completely different case.

    EvIo tries to parse the stream resource based on the information about the different possible types of resources which which is available at compile time. The only place in the code that throws the exception is this:

    #ifdef PHP_EV_USE_SOCKETS
        ...
    #else
                zend_throw_exception(zend_exception_get_default(), "Expected a valid PHP stream resource", 0);
    #endif
    

    And the PHP_EV_USE_SOCKETS constant is only defined if the sockets extension is available at compile time. The presence of the exception is a clear sign of the fact that the sockets extension was not available when you built ev.


    I don’t know what kind of (Linux?) distribution are you running and how did you build ev, but what you need to do is the following:

    1. Make sure that PHP is built with --enable-sockets (it is present in the output of your php-config, OK).
    2. Make sure that the PHP development files (like the /ext/sockets/php_sockets.h C header which you can find in the php-dev package in Ubuntu, for instance) are installed and available at the standard locations (like /usr/include/)
    3. Rebuild ev either manually or using pecl install ev
    4. Put extension=sockets.so before extension=ev.so (e.g. enable sockets in some 20-sockets.ini and the ev extension in some 999-ev.ini)
    5. Make sure that both ev and sockets are present in the output of php -m

    Now try to run the demo script. If it fails again, then please consider creating a docker image so that I can pull it and see what’s happening there.

  3. Log in to comment