Source for file MPM-prefork.php
Documentation is available at MPM-prefork.php
class Net_Server_Driver_Multiprocess_MPM extends PHP_Fork {
function Net_Server_Driver_Multiprocess_MPM (&$pool, &$server)
$this->PHP_Fork ("Processor-3");
$this->_server = &$server;
$this->_numThreads = $this->_server->_numThreads;
$this->_startPool = $this->_server->_startPool;
$this->_maxIdleTime = $this->_server->_maxIdleTime;
$this->_threadPool = &$pool;
for ($i = 0; $i < count($this->_threadPool)-1; $i++ ) {
$this->_threadPool[$i]->setVariable ("threadWorking", false );
// this global value is true until the stopAllProcesses() method
// sets it to false before stopping the processes
$GLOBALS['mpm_run'] = true;
// Dynamic pool regulation
while ($GLOBALS['mpm_run']) {
for ($i = 0; $i < count($this->_threadPool)-1; $i++ ) {
if ($this->_threadPool[$i]->getVariable ("threadWorking")) {
$nextIndex = count($this->_threadPool);
$this->setVariable ("workingProcesses", $working);
$this->setVariable ("runningProcesses", $nextIndex);
print ($working . " clients connected, " . $nextIndex . " threads avaible" . "\n");
if (($nextIndex - $working) <= 1 && $nextIndex < $this->_numThreads) {
// let's see if there're few threads avaible...
print ("Starting new thread with id " . $nextIndex . "\n");
$this->_threadPool[$nextIndex] = &new Net_Server_Driver_Multiprocess_Processor ($nextIndex, $this->_server);
$this->_threadPool[$nextIndex]->start ();
print ("Started Processor " . $nextIndex . " with PID " . $this->_threadPool[$nextIndex]->getPid () . "\n");
for ($key = count($listener)-1; $key > $this->_startPool; $key-- ) {
$thread = $listener[$key];
if ($thread->getLastAlive () > $this->_maxIdleTime) {
// this thread is not used since _maxIdleTime; let's kill it...
$threadName = $thread->getName ();
$this->_sendDebugMessage ("killing " . $threadName . "...\n");
$this->_sendDebugMessage ("Now avaible: " . count($listener) . " threads...\n");
function getProcOverview ()
return array ('working' => $this->getVariable ("workingProcesses"),
'running' => $this->getVariable ("runningProcesses"));
function getProcList ($params)
foreach($this->_threadPool as $thread) {
$procList[] = array ($thread->getName (), $thread->getPid (), $thread->getVariable ("threadWorking"));
} else return $this->register_callback_func (func_get_args(), __FUNCTION__ );
function stopAllProcesses ()
// this is needed otherwise the run() method will continue to check
// for dead processes status raising a fatal exception.
$GLOBALS['mpm_run'] = false;
foreach($this->_threadPool as $thread) {
print "Stopping " . $thread->getName () . "\n";
} else return $this->register_callback_func (func_get_args(), __FUNCTION__ );
Documentation generated on Mon, 11 Mar 2019 15:47:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|