multithreading.php
changeset 53 a6b339665650
parent 48 d643bfb862d8
child 68 32f6e2ee15ab
equal deleted inserted replaced
52:ab3541465382 53:a6b339665650
   128   
   128   
   129   public function __construct()
   129   public function __construct()
   130   {
   130   {
   131     global $threader_instances;
   131     global $threader_instances;
   132     
   132     
   133     declare(ticks=1);
   133     if ( function_exists('pcntl_signal') )
   134     
   134     {
   135     $threader_instances[] =& $this;
   135       declare(ticks=1);
   136     
   136       
   137     pcntl_signal(SIGUSR2, 'Threader_SigUsr2');
   137       $threader_instances[] =& $this;
   138     pcntl_signal(SIGCHLD, 'Threader_SigChld');
   138       
       
   139       pcntl_signal(SIGUSR2, 'Threader_SigUsr2');
       
   140       pcntl_signal(SIGCHLD, 'Threader_SigChld');
       
   141     }
   139     
   142     
   140     $this->json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
   143     $this->json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
   141     $this->parent_pid = getmypid();
   144     $this->parent_pid = getmypid();
   142   }
   145   }
   143   
   146   
   168     {
   171     {
   169       // we are the child.
   172       // we are the child.
   170       fclose($socket_pair[1]);
   173       fclose($socket_pair[1]);
   171       $this->parent_sock = $socket_pair[0];
   174       $this->parent_sock = $socket_pair[0];
   172       $this->is_child = true;
   175       $this->is_child = true;
   173       return FORK_CHILD;
   176       return self::FORK_CHILD;
   174     }
   177     }
   175   }
   178   }
   176   
   179   
   177   /**
   180   /**
   178    * Are we a child?
   181    * Are we a child?