|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-05-27 12:57 UTC] dietrich dot ayala at foundstone dot com
1. it doesn't seem to be doing non-busy waits. If the remote host takes a long time to respond, the CPU is still maxed until a response is received. 2. I've had repeatable situations where the server returned a response right away, but stream_select() didn't return for (in our repeatable case) 10 mins. What's it's criteria for responding? What will it do if I pass a stream to it, which has already had everything read from it, but is persistent, so there's no EOF/line-break/anything? It seems that whatever its return criteria is, it isn't met sometimes. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 21:00:01 2025 UTC |
"cannot reproduce" is different from "didn't attempt to reproduce" ;) Also, this is very critical! PHP doesn't look so good when even the smallest network activity could bring the box to a crawl if anything besides PHP is active. This is especially frustrating when the server is localhost, so you have all your progs having to battle PHP for CPU, and PHP doesn't even need it, except to busy-wait! Here's the repro script. This brings CPU to 100% every time on my win2k box. I set up a server that sleeps for a few seconds before responding, and that showed it even more clearly than this example. <?php $host = 'd-w2kserv'; $port = 80; // open connection if(!$fp = pfsockopen($host, $port, $errno, $error_str)){ die('error: '.$error_str.$phperrormsg); } else { // write data $requestMsg = "GET / HTTP/1.1\r\nHost: $host\r\n\r\n"; if(!@fwrite($fp, $requestMsg)) { die('error: '.$phperrormsg); } // read data do { // array of connections $read = array($fp); // use stream_select() for non-busy wait if (false === ($num_changed_streams = stream_select($read, $write = NULL, $except = NULL, 0))) { die('Stream_select returned error: '.$phperrormsg); // At least on one of the streams something interesting happened } elseif ($num_changed_streams > 0) { if( !$data = @fgets($fp, 8192) ){ die('couldnt get data from socket, or socket returned no data'); } print $data; // no more data if (feof($fp) || $data === false || strlen($data) == 0) { break; } } } while(true); } ?>