multithreading.php
changeset 68 32f6e2ee15ab
parent 53 a6b339665650
child 76 487a16c7117c
--- a/multithreading.php	Sun Jan 04 22:56:57 2009 -0500
+++ b/multithreading.php	Tue May 26 15:24:26 2009 -0400
@@ -37,12 +37,13 @@
 
 function Threader_SigUsr2()
 {
-  global $threader_instances;
+  global $threader_instances, $threader_notick;
+  if ( @$threader_notick )
+    return;
   foreach ( $threader_instances as &$mt )
   {
     if ( is_object($mt) )
     {
-      $parchild = $mt->is_child() ? 'child' : 'parent';
       $mt->event_sigusr2();
     }
   }
@@ -136,8 +137,8 @@
       
       $threader_instances[] =& $this;
       
+      pcntl_signal(SIGCHLD, 'Threader_SigChld');
       pcntl_signal(SIGUSR2, 'Threader_SigUsr2');
-      pcntl_signal(SIGCHLD, 'Threader_SigChld');
     }
     
     $this->json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
@@ -273,6 +274,7 @@
     if ( $this->is_child() )
     {
       // this is easy - the parent sent the signal.
+      @stream_set_blocking($this->parent_sock, 0);
       $command = rtrim(fgets($this->parent_sock, 102400), "\n");
     }
     else
@@ -281,8 +283,7 @@
       // of time and try to read; if we get something, awesome.
       foreach ( $this->ipc_sockets as $pid => $socket )
       {
-        // 1000 microseconds = 1/80th of the time it takes you to blink.
-        @stream_set_timeout($socket, 0, 1000);
+        @stream_set_blocking($socket, 0);
         $command = rtrim(@fgets($socket, 102400), "\n");
         if ( !empty($command) )
         {