Repository navigation
Warning: feof(): 60 is not a valid stream resource in .. /src/Socket/Connection.php on line 18 #4
Description
Activity
I have the same error when the connection is closed from a
datalistener.A solution : detect the end of stream before dispatching
dataevent.if ('' === $data || false === $data || feof($stream)) { $this->end(); } else { $this->emit('data', array($data, $this)); }
A temporary solution is to specify
falseon closure output :$conn->end(false);
Would you be able to provide instructions on how to replicate this error?
I got (almost) the same error this morning while working on the DNS basic usage example. Maybe this could help replicate the warning:
<?php // dns.php error_reporting(PHP_INT_MAX); require_once 'vendor/autoload.php'; $loop = \React\EventLoop\Factory::create(); $factory = new \React\Dns\Resolver\Factory(); $dns = $factory->create('8.8.8.8', $loop); $dns->resolve($argv[1]) ->then( function ($ip) { echo "Host: $ip\n"; }, function ($e) { echo "Error: {$e->getMessage()}\n"; } ); $loop->run();
Running
php dns.php jeremykendall.netreturned:$ php dns.php jeremykendall.net Host: 50.57.159.57 PHP Warning: feof(): 33 is not a valid stream resource in /Users/jeremykendall/dev/explore-react/vendor/react/react/src/Socket/Connection.php on line 18 PHP Stack trace: PHP 1. {main}() /Users/jeremykendall/dev/explore-react/dns.php:0 PHP 2. React\EventLoop\StreamSelectLoop->run() /Users/jeremykendall/dev/explore-react/dns.php:17 PHP 3. React\EventLoop\StreamSelectLoop->waitForStreamActivity() /Users/jeremykendall/dev/explore-react/vendor/react/react/src/EventLoop/StreamSelectLoop.php:201 PHP 4. call_user_func:{/Users/jeremykendall/dev/explore-react/vendor/react/react/src/EventLoop/StreamSelectLoop.php:227}() /Users/jeremykendall/dev/explore-react/vendor/react/react/src/EventLoop/StreamSelectLoop.php:227 PHP 5. React\Socket\Connection->handleData() /Users/jeremykendall/dev/explore-react/vendor/react/react/src/EventLoop/StreamSelectLoop.php:227 PHP 6. feof() /Users/jeremykendall/dev/explore-react/vendor/react/react/src/Socket/Connection.php:18 Warning: feof(): 33 is not a valid stream resource in /Users/jeremykendall/dev/explore-react/vendor/react/react/src/Socket/Connection.php on line 18 Call Stack: 0.0002 238968 1. {main}() /Users/jeremykendall/dev/explore-react/dns.php:0 0.0060 906616 2. React\EventLoop\StreamSelectLoop->run() /Users/jeremykendall/dev/explore-react/dns.php:17 0.0062 907648 3. React\EventLoop\StreamSelectLoop->waitForStreamActivity() /Users/jeremykendall/dev/explore-react/vendor/react/react/src/EventLoop/StreamSelectLoop.php:201 0.0515 908184 4. call_user_func:{/Users/jeremykendall/dev/explore-react/vendor/react/react/src/EventLoop/StreamSelectLoop.php:227}() /Users/jeremykendall/dev/explore-react/vendor/react/react/src/EventLoop/StreamSelectLoop.php:227 0.0515 908312 5. React\Socket\Connection->handleData() /Users/jeremykendall/dev/explore-react/vendor/react/react/src/EventLoop/StreamSelectLoop.php:227 0.0527 913368 6. feof() /Users/jeremykendall/dev/explore-react/vendor/react/react/src/Socket/Connection.php:18Environment:
- Mac OS X 10.9.4
- PHP 5.5.12
- React 0.4.1
$ php -v PHP 5.5.12 (cli) (built: May 23 2014 15:03:24) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Xdebug v2.2.4, Copyright (c) 2002-2014, by Derick RethansThe solution suggested by brieucthomas did work for me though I had to check for NULL data as well.
Similar problem here running
http-clienton windows:PHP Warning: feof(): 52 is not a valid stream resource in C:\andi\htdocs\vz\vendor\react\react\src\Socket\Connection.ph p on line 18 PHP Stack trace: PHP 1. {main}() C:\andi\htdocs\vz\http-client.php:0 PHP 2. React\EventLoop\StreamSelectLoop->run() C:\andi\htdocs\vz\http-client.php:40 PHP 3. React\EventLoop\StreamSelectLoop->waitForStreamActivity() C:\andi\htdocs\vz\vendor\react\react\src\EventLoop\St reamSelectLoop.php:201 PHP 4. call_user_func:{C:\andi\htdocs\vz\vendor\react\react\src\EventLoop\StreamSelectLoop.php:227}() C:\andi\htdocs\v z\vendor\react\react\src\EventLoop\StreamSelectLoop.php:227 PHP 5. React\Socket\Connection->handleData() C:\andi\htdocs\vz\vendor\react\react\src\EventLoop\StreamSelectLoop.php:2 27 PHP 6. feof() C:\andi\htdocs\vz\vendor\react\react\src\Socket\Connection.php:18Update: fix from @webzak confirmed working.
Any chance this is gonna be fixed? Stumpes me every time I'm doing a composer install :(
@jeremykendall, thanks for your script! We can now successfully reproduce this issue. I believe this to be an issue in the react/dns component. Would you care to report the error over in the corresponding project?
This might also be the reason why @andig experiences the same issue in the react/http-client component. It uses the react/dns component to resolve hostnames to IPs. @andig, would you care to verify that this should work when you use IPs instead of hostnames?
The underlying problem appears to be that the
Connectionrepresents an incoming server side connection. It MUST NOT be used as an outgoing connection in a client side context. I've just filed ticket #13 to update the documentation to reflect this.Does anybody else experience the same issue in a different context?
would you care to verify that this should work when you use IPs instead of hostnames?
Verified - this is my current workaround.
Connection represents an incoming server side connection
Does that mean that a new type of client connection needs to be developed now? Would this be goal of this issue then?
@brieucthomas solution worked for me. No warning anymore.
Thanks for the confirmation @andig. The
React\Socket\Connectionmust only be used in a server side context, all other streams should use theReact\Stream\Streamclass instead. I've filed PR #13 to update the documentation to reflect this, but otherwise everything is already there.Thanks for reporting back @miladr, would you care to also describe how to reproduce the issue you were having?
See also my above comment for details. As it currently stands it appears to be caused by using
React\Socket\Connectionin places where aReact\Stream\Streamshould be used instead.You are welcome.
I'm creating a Http testing tool for our project.
I used this code to send Http requests.<?php require 'vendor/autoload.php'; $loop = React\EventLoop\Factory::create(); $dnsResolverFactory = new \React\Dns\Resolver\Factory(); $dnsResolver = $dnsResolverFactory->createCached('8.8.8.8', $loop); $factory = new \React\HttpClient\Factory(); $client = $factory->create($loop, $dnsResolver); foreach(range(1,10) as $index){ echo "Request #" . $index . " Had been sent at " . date("i:s",time()) . PHP_EOL; $request = $client->request('GET', 'http://httpbin.org/get?index=' . $index); $buffer = ''; $request->on( 'response', function ($response) use (&$buffer) { $response->on( 'data', function ($data) use (&$buffer) { $buffer .= $data; } ); } ); $request->on( 'end', function () use (&$buffer , $index) { echo "Request #" . $index . " completed at " . date("i:s",time()) . PHP_EOL; } ); $request->end(false); } $loop->run();
Thanks for the confirmation @andig. The
React\Socket\Connectionmust only be used in a server side context, all other streams should use theReact\Stream\Streamclass instead. I've filed PR #13 to update the documentation to reflect this,I'm having my slow day. https://github.com/reactphp/dns/blob/master/src/Query/Executor.php uses
React\Socket\Connectionwhich should not be the case?but otherwise everything is already there.
So this is the piece that needs to be fixed and is currently missing imho?
I've forwarded this error report to the component that is actually the source of this error:
Afaict this component does not need to be patched.
Can we close this ticket?
@clue I vote yes. Thanks for your hard work on this.
@clue that's what I've meant- thank you!
When data are short after reading with stream_socket_recvfrom() stream type changes from 'stream' to 'Unknown' and feof($stream) generates warning.
The possible fix is to add check of type before feof()
if ('' === $data || false === $data || get_resource_type($stream) == 'Unknown' || feof($stream))