note 78147 added to function.stream-select

From: Date: Sun, 30 Sep 2007 05:28:11 +0000
Subject: note 78147 added to function.stream-select
Groups: php.notes 
Request: Send a blank email to php-notes+get-130942@lists.php.net to get a copy of this message
Simple stream_select wrapper.. Returns the first stream in the array, and sets parameter 2 to the key (So that it is easy to identify what received data): <?php function select($array, &$vkey, $timeout=0){ $select = array(); $null = NULL; foreach($array as $key => $sock){ $x = count($select); $select[$x] = $sock; $keys[$x] = $key; } if(stream_select($select, $null, $null, $timeout)){ foreach($keys as $key){ if($array[$key] == $select[0]){ $vkey = $key; return($select[0]); } } } } $streams = array("foo" => $stream_one, "bar" => $stream_two); // Create an array of two (already existant) streams. if($new = select($streams, $key, 60)){ //Sets $new to the resource that next gets new data, and $key to either "foo", or "bar", depending which one it is. echo $key.":".stream_get_line($new, 2048)."\n"; } ?> ---- Server IP: 203.89.181.186 Probable Submitter: 203.97.238.106 ---- Manual Page -- http://www.php.net/manual/en/function.stream-select.php Edit -- https://master.php.net/note/edit/78147 Del: integrated -- https://master.php.net/note/delete/78147/integrated Del: useless -- https://master.php.net/note/delete/78147/useless Del: bad code -- https://master.php.net/note/delete/78147/bad+code Del: spam -- https://master.php.net/note/delete/78147/spam Del: non-english -- https://master.php.net/note/delete/78147/non-english Del: in docs -- https://master.php.net/note/delete/78147/in+docs Del: other reasons-- https://master.php.net/note/delete/78147 Reject -- https://master.php.net/note/reject/78147 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130942) next »