note 66228 added to function.socket-select

From: Date: Wed, 17 May 2006 07:01:56 +0000
Subject: note 66228 added to function.socket-select
Groups: php.notes 
Request: Send a blank email to php-notes+get-111479@lists.php.net to get a copy of this message
Just for the sake of conversation (and hopefully this code helps someone), this is the solution I worked out pretty much at the same time as I posted my first comment: (PHP4) <?php $modules = array('module1','module2','module3'); // Initialize each module foreach($modules as $module) { ${$module} =& myScript_Factory::factory($module); } // Instruct all modules to connect foreach($modules as $module) { ${$module}->connect(); } //Main Thread while(TRUE) { $sockets = array(); //Check that each module is still connected, re-establish connection if it's not foreach($modules as $module) { $_handle_name = $module.'_handle'; if(${$module}->{$_handle_name}) { $sockets[] = ${$module}->{$_handle_name}; } else { ${$module}->connect(); } } $num_changed_streams = socket_select($sockets, $write = NULL, $except = NULL, 0, 50000); if ($num_changed_streams > 0) { foreach($sockets as $module => $sock) { foreach($modules as $module) { $_handle_name = $module.'_handle'; if($sock == ${$module}->$_handle_name) { ${$module}->recv(); } } } } } ?> ---- Server IP: 216.194.113.175 Probable Submitter: 68.228.235.15 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.socket-select.php Edit -- http://master.php.net/note/edit/66228 Del: integrated -- http://master.php.net/note/delete/66228/integrated Del: useless -- http://master.php.net/note/delete/66228/useless Del: bad code -- http://master.php.net/note/delete/66228/bad+code Del: spam -- http://master.php.net/note/delete/66228/spam Del: non-english -- http://master.php.net/note/delete/66228/non-english Del: in docs -- http://master.php.net/note/delete/66228/in+docs Del: other reasons-- http://master.php.net/note/delete/66228 Reject -- http://master.php.net/note/reject/66228 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#111479) next »