note 43473 added to function.stream-select

From: Date: Tue, 22 Jun 2004 15:30:23 +0000
Subject: note 43473 added to function.stream-select
Groups: php.notes 
Request: Send a blank email to php-notes+get-71505@lists.php.net to get a copy of this message
If you want to set an absolute maximum execution time for stream_select in a loop, it's important to decrement the max_time value passed to stream_select. <?php // The maximum time for execution in milliseconds $maxtime = 200000; // The time the loop started $starttime = microtime(true); // Original array of sockets $r = $orig_sockets; // The function to calculate the timeout function calctimeout($maxtime, $starttime) { return $maxtime - ((microtime(true) - $starttime) * 1000000); } while (stream_select($r, $w = null, $e = null, 0, calctimeout($maxtime, $starttime)) !== 0) { // loop through the sockets that showed activity foreach ($r as $socket) { // $socket talked } // stream_select modifies the contents of $r // in a loop we should replace it with the original $r = $orig_sockets; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.stream-select.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43473 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43473&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43473&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#71505) next »