本文整理汇总了PHP中PHPDaemon\Core\Daemon::getStateOfWorkers方法的典型用法代码示例。如果您正苦于以下问题:PHP Daemon::getStateOfWorkers方法的具体用法?PHP Daemon::getStateOfWorkers怎么用?PHP Daemon::getStateOfWorkers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPDaemon\Core\Daemon
的用法示例。
在下文中一共展示了Daemon::getStateOfWorkers方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Called when request iterated.
* @return integer Status.
*/
public function run()
{
$stime = microtime(true);
$this->header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Server status.</title>
</head>
<body>
<br/>Uptime: <b><?php
echo DateTime::diffAsText(Daemon::$startTime, time());
?>
</b>
<br/><br/><b>State of workers:</b><?php
$stat = Daemon::getStateOfWorkers();
?>
<br/>Idle: <?php
echo $stat['idle'];
?>
<br/>Busy: <?php
echo $stat['busy'];
?>
<br/>Total alive: <?php
echo $stat['alive'];
?>
<br/>Shutdown: <?php
echo $stat['shutdown'];
?>
<br/>Pre-init: <?php
echo $stat['preinit'];
?>
<br/>Wait-init: <?php
echo $stat['waitinit'];
?>
<br/>Init: <?php
echo $stat['init'];
?>
<br/>
<br/>Request took: <?php
printf('%f', round(microtime(true) - $stime, 6));
?>
</body>
</html>
<?php
}
示例2: run
/**
* Called when request iterated.
* @return integer Status.
*/
public function run()
{
$this->sessionStart();
try {
$this->header('Content-Type: text/html');
$this->setcookie('testcookie', '1');
} catch (\PHPDaemon\Request\RequestHeadersAlreadySent $e) {
}
$this->registerShutdownFunction(function () {
?>
</html>
<?php
});
if (!isset($_SESSION['counter'])) {
$_SESSION['counter'] = 0;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>It works!</title>
</head>
<body>
<h1>It works! Be happy! ;-) </h1>
*Hello world!<br/>
Testing Error Message: <?php
trigger_error('_text_of_notice_');
?>
<br/>Counter of requests to this Application Instance: <b><?php
echo ++$this->appInstance->counter;
?>
</b>
<br />Counter in session: <?php
echo ++$_SESSION['counter'];
?>
<br/>Memory usage: <?php
$mem = memory_get_usage();
echo $mem / 1024 / 1024;
?>
MB. (<?php
echo $mem;
?>
)
<br/>Memory real usage: <?php
$mem = memory_get_usage(true);
echo $mem / 1024 / 1024;
?>
MB. (<?php
echo $mem;
?>
)
<br/>My PID: <?php
echo getmypid();
?>
.
<?php
$user = posix_getpwuid(posix_getuid());
$group = posix_getgrgid(posix_getgid());
?>
<br/>My user/group: <?php
echo $user['name'] . '/' . $group['name'];
$displaystate = true;
if ($displaystate) {
?>
<br/><br/><b>State of workers:</b><?php
$stat = \PHPDaemon\Core\Daemon::getStateOfWorkers();
?>
<br/>Idle: <?php
echo $stat['idle'];
?>
<br/>Busy: <?php
echo $stat['busy'];
?>
<br/>Total alive: <?php
echo $stat['alive'];
?>
<br/>Shutdown: <?php
echo $stat['shutdown'];
?>
<br/>Pre-init: <?php
echo $stat['preinit'];
?>
<br/>Init: <?php
echo $stat['init'];
?>
<br/>
<?php
}
?>
<br/><br/>
<br/><br/>
<form action="<?php
echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES);
?>
//.........这里部分代码省略.........
示例3: init
//.........这里部分代码省略.........
}
if (isset(Daemon::$config->minspareworkers->value) && Daemon::$config->minspareworkers->value > 0 && isset(Daemon::$config->maxspareworkers->value) && Daemon::$config->maxspareworkers->value > 0) {
if (Daemon::$config->minspareworkers->value > Daemon::$config->maxspareworkers->value) {
Daemon::log('\'minspareworkers\' cannot be greater than \'maxspareworkers\'.');
$error = true;
}
}
if (isset(Daemon::$config->addincludepath->value)) {
ini_set('include_path', ini_get('include_path') . ':' . implode(':', Daemon::$config->addincludepath->value));
}
if (isset(Daemon::$config->minworkers->value) && isset(Daemon::$config->maxworkers->value)) {
if (Daemon::$config->minworkers->value > Daemon::$config->maxworkers->value) {
Daemon::$config->minworkers->value = Daemon::$config->maxworkers->value;
}
}
if ($runmode === 'start') {
if ($error === FALSE) {
Bootstrap::start();
} else {
exit(6);
}
} elseif ($runmode === 'runworker') {
if ($error === FALSE) {
Bootstrap::runworker();
} else {
exit(6);
}
} elseif ($runmode === 'status' || $runmode === 'fullstatus') {
$status = Bootstrap::$pid && Thread\Generic::ifExistsByPid(Bootstrap::$pid);
echo '[STATUS] phpDaemon ' . Daemon::$version . ' is ' . ($status ? 'running' : 'NOT running') . ' (' . Daemon::$config->pidfile->value . ").\n";
if ($status && $runmode === 'fullstatus') {
echo 'Uptime: ' . DateTime::diffAsText(filemtime(Daemon::$config->pidfile->value), time()) . "\n";
Daemon::$shm_wstate = new ShmEntity(Daemon::$config->pidfile->value, Daemon::SHM_WSTATE_SIZE, 'wstate');
$stat = Daemon::getStateOfWorkers();
echo "State of workers:\n";
echo "\tTotal: " . $stat['alive'] . "\n";
echo "\tIdle: " . $stat['idle'] . "\n";
echo "\tBusy: " . $stat['busy'] . "\n";
echo "\tShutdown: " . $stat['shutdown'] . "\n";
echo "\tPre-init: " . $stat['preinit'] . "\n";
echo "\tInit: " . $stat['init'] . "\n";
}
echo "\n";
} elseif ($runmode === 'update') {
if (!Bootstrap::$pid || !posix_kill(Bootstrap::$pid, SIGHUP)) {
echo '[UPDATE] ERROR. It seems that phpDaemon is not running' . (Bootstrap::$pid ? ' (PID ' . Bootstrap::$pid . ')' : '') . ".\n";
}
} elseif ($runmode === 'reopenlog') {
if (!Bootstrap::$pid || !posix_kill(Bootstrap::$pid, SIGUSR1)) {
echo '[REOPEN-LOG] ERROR. It seems that phpDaemon is not running' . (Bootstrap::$pid ? ' (PID ' . Bootstrap::$pid . ')' : '') . ".\n";
}
} elseif ($runmode === 'reload') {
if (!Bootstrap::$pid || !posix_kill(Bootstrap::$pid, SIGUSR2)) {
echo '[RELOAD] ERROR. It seems that phpDaemon is not running' . (Bootstrap::$pid ? ' (PID ' . Bootstrap::$pid . ')' : '') . ".\n";
}
} elseif ($runmode === 'restart') {
if ($error === FALSE) {
Bootstrap::stop(2);
Bootstrap::start();
}
} elseif ($runmode === 'hardrestart') {
Bootstrap::stop(3);
Bootstrap::start();
} elseif ($runmode === 'ipcpath') {
$i = Daemon::$appResolver->getInstanceByAppName('\\PHPDaemon\\IPCManager\\IPCManager');
echo $i->getSocketUrl() . PHP_EOL;
示例4: callMPM
/**
* @return int
*/
protected function callMPM()
{
$state = Daemon::getStateOfWorkers($this);
if (isset(Daemon::$config->mpm->value) && is_callable(Daemon::$config->mpm->value)) {
return call_user_func(Daemon::$config->mpm->value, $this, $state);
}
$upToMinWorkers = Daemon::$config->minworkers->value - $state['alive'];
$upToMaxWorkers = Daemon::$config->maxworkers->value - $state['alive'];
$upToMinSpareWorkers = Daemon::$config->minspareworkers->value - $state['idle'];
if ($upToMinSpareWorkers > $upToMaxWorkers) {
$upToMinSpareWorkers = $upToMaxWorkers;
}
$n = max($upToMinSpareWorkers, $upToMinWorkers);
if ($n > 0) {
//Daemon::log('minspareworkers = '.Daemon::$config->minspareworkers->value);
//Daemon::log('maxworkers = '.Daemon::$config->maxworkers->value);
//Daemon::log('maxspareworkers = '.Daemon::$config->maxspareworkers->value);
//Daemon::log(json_encode($state));
//Daemon::log('upToMinSpareWorkers = ' . $upToMinSpareWorkers . ' upToMinWorkers = ' . $upToMinWorkers);
Daemon::log('Spawning ' . $n . ' worker(s)');
$this->spawnWorkers($n);
return $n;
}
$a = ['default' => 0];
if (Daemon::$config->maxspareworkers->value > 0) {
// if MaxSpareWorkers enabled, we have to stop idle workers, keeping in mind the MinWorkers
$a['downToMaxSpareWorkers'] = min($state['idle'] - Daemon::$config->maxspareworkers->value, $state['alive'] - Daemon::$config->minworkers->value);
}
$a['downToMaxWorkers'] = $state['alive'] - $state['reloading'] - Daemon::$config->maxworkers->value;
$n = max($a);
if ($n > 0) {
//Daemon::log('down = ' . json_encode($a));
//Daemon::log(json_encode($state));
Daemon::log('Stopping ' . $n . ' worker(s)');
$this->stopWorkers($n);
return -$n;
}
return 0;
}