On Fri, 7 Jan 2005, Gabriel Wicke wrote:
The code that reads from the socket:
while (strlen($res) < 100 && $esc < 200 ) { $res .= @fread($sockets[$s],512); $esc++; usleep(20); }
This means that it won't try to read from the socket forever, and the waiting adds up to 0.004 seconds. Not sure about the fread's timeout, iirc it's fairly low if it waits at all, i forget. Come to think of it, usleep should probably wait a bit longer in less cycles, not sure why i picked it that low- i think it also consumes a some cpu time in php.
In my experience, usleep() cannot be shorter than a single time slice fromt the Linux scheduler, which for 2.6 kernels should be 1 millisecond.
So that code is waiting up to 200 milliseconds, with negligible CPU overhead, unless of course PHP does things differently. But to sleep less than a timeslice you need to busy sleep, so the CPU would be taxed at 100% in that case.
Alfio