note 66228 deleted from function.socket-select by nlopess
| From: | nlopess@php.net | Date: | Wed, 17 May 2006 09:42:29 +0000 |
| Subject: | note 66228 deleted from function.socket-select by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-111487@lists.php.net to get a copy of this message | ||
Note Submitter: crimson@NOSPAMtechnologistDOTcom
----
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();
}
}
}
}
}
?>