Net_Server
[ class tree: Net_Server ] [ index: Net_Server ] [ all elements ]

Source for file MPM-prefork.php

Documentation is available at MPM-prefork.php

  1. <?php
  2. declare (ticks = 1);
  3. class Net_Server_Driver_Multiprocess_MPM extends PHP_Fork {
  4.  
  5.     var $_threadPool;
  6.     var $_server;
  7.     var $_numThreads;
  8.     var $_startPool;
  9.     var $_maxIdleTime;
  10.  
  11.     function Net_Server_Driver_Multiprocess_MPM(&$pool&$server)
  12.     {
  13.         $this->PHP_Fork("Processor-3");
  14.         $this->_server &$server;
  15.  
  16.         $this->_numThreads $this->_server->_numThreads;
  17.         $this->_startPool $this->_server->_startPool;
  18.         $this->_maxIdleTime $this->_server->_maxIdleTime;
  19.  
  20.         $this->_threadPool &$pool;
  21.     
  22.  
  23.     function run()
  24.     
  25.  
  26.         // reset shared mem
  27.         for ($i = 0; $i count($this->_threadPool)-1; $i++{
  28.             $this->_threadPool[$i]->setVariable("threadWorking"false);
  29.         
  30.         // this global value is true until the stopAllProcesses() method
  31.         // sets it to false before stopping the processes
  32.         $GLOBALS['mpm_run'= true; 
  33.         // Dynamic pool regulation
  34.         while ($GLOBALS['mpm_run']{
  35.              print "checking...";
  36.             $working = 0;
  37.  
  38.             for ($i = 0; $i count($this->_threadPool)-1; $i++{
  39.                 if ($this->_threadPool[$i]->getVariable("threadWorking")) {
  40.                     $working++;
  41.                 
  42.             
  43.             $nextIndex count($this->_threadPool);
  44.  
  45.             $this->setVariable("workingProcesses"$working);
  46.             $this->setVariable("runningProcesses"$nextIndex)
  47.             print($working " clients connected, " $nextIndex " threads avaible" "\n");
  48.             if (($nextIndex $working<= 1 && $nextIndex $this->_numThreads{
  49.                 // let's see if there're few threads avaible...
  50.                 print("Starting new thread with id " $nextIndex "\n");
  51.  
  52.                 $this->_threadPool[$nextIndex&new Net_Server_Driver_Multiprocess_Processor($nextIndex$this->_server);
  53.                 $this->_threadPool[$nextIndex]->start();
  54.                 print("Started Processor " $nextIndex " with PID " $this->_threadPool[$nextIndex]->getPid("\n");
  55.                 sleep(2);
  56.             else {
  57.  
  58.                 for ($key count($listener)-1; $key $this->_startPool$key--{
  59.                     $thread $listener[$key];
  60.                     if ($thread->getLastAlive($this->_maxIdleTime{
  61.                         // this thread is not used since _maxIdleTime; let's kill it...
  62.                         $threadName $thread->getName();
  63.                         $this->_sendDebugMessage("killing " $threadName "...\n");
  64.                         $thread->stop();
  65.                         array_splice($listener$key1);
  66.                         $this->_sendDebugMessage("Now avaible: " count($listener" threads...\n");
  67.                     }
  68.                 }
  69.  
  70.             
  71.             sleep(1);
  72.         
  73.  
  74.     
  75.  
  76.     function getProcOverview()
  77.     {
  78.         return array('working' => $this->getVariable("workingProcesses"),
  79.             'running' => $this->getVariable("runningProcesses"));
  80.     
  81.  
  82.     function getProcList($params)
  83.     {
  84.         if ($this->_isChild{
  85.             $procList = array();
  86.             foreach($this->_threadPool as $thread{
  87.                 $procList[= array($thread->getName()$thread->getPid()$thread->getVariable("threadWorking"));
  88.             
  89.             return $procList;
  90.         else return $this->register_callback_func(func_get_args()__FUNCTION__);
  91.     
  92.  
  93.     function stopAllProcesses()
  94.     {
  95.         if ($this->_isChild{
  96.             // this is needed otherwise the run() method will continue to check
  97.             // for dead processes status raising a fatal exception.
  98.             $GLOBALS['mpm_run'= false;
  99.  
  100.             foreach($this->_threadPool as $thread{
  101.                 print "Stopping " $thread->getName("\n";
  102.                 $thread->stop();
  103.             
  104.             return true;
  105.         else return $this->register_callback_func(func_get_args()__FUNCTION__);
  106.     
  107. }

Documentation generated on Mon, 11 Mar 2019 15:47:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.