本文整理汇总了PHP中Daemon::getStateOfWorkers方法的典型用法代码示例。如果您正苦于以下问题:PHP Daemon::getStateOfWorkers方法的具体用法?PHP Daemon::getStateOfWorkers怎么用?PHP Daemon::getStateOfWorkers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Daemon
的用法示例。
在下文中一共展示了Daemon::getStateOfWorkers方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Runtime of Master process
* @return void
*/
public function run()
{
Daemon::$process = $this;
$this->prepareSystemEnv();
class_exists('Timer');
// ensure loading this class
gc_enable();
$this->eventBase = event_base_new();
$this->registerEventSignals();
FS::initEvent();
$this->fileWatcher = new FileWatcher();
$this->workers = new ThreadCollection();
$this->collections['workers'] = $this->workers;
Daemon::$appResolver = (require Daemon::$config->path->value);
$this->IPCManager = Daemon::$appResolver->getInstanceByAppName('IPCManager');
Daemon::$appResolver->preload(true);
$this->callbacks = new SplStack();
$this->spawnWorkers(min(Daemon::$config->startworkers->value, Daemon::$config->maxworkers->value));
Timer::add(function ($event) use(&$cbs) {
$self = Daemon::$process;
static $c = 0;
++$c;
if ($c > 0xfffff) {
$c = 1;
}
if ($c % 10 == 0) {
$self->workers->removeTerminated(true);
gc_collect_cycles();
} else {
$self->workers->removeTerminated();
}
if (isset(Daemon::$config->mpm->value) && is_callable(Daemon::$config->mpm->value)) {
call_user_func(Daemon::$config->mpm->value);
} else {
// default MPM
$state = Daemon::getStateOfWorkers($self);
if ($state) {
$n = max(min(Daemon::$config->minspareworkers->value - $state['idle'], Daemon::$config->maxworkers->value - $state['alive']), Daemon::$config->minworkers->value - $state['alive']);
if ($n > 0) {
Daemon::log('Spawning ' . $n . ' worker(s).');
$self->spawnWorkers($n);
event_base_loopbreak($self->eventBase);
}
$n = min($state['idle'] - Daemon::$config->maxspareworkers->value, $state['alive'] - Daemon::$config->minworkers->value);
if ($n > 0) {
Daemon::log('Stopping ' . $n . ' worker(s).');
$self->stopWorkers($n);
}
}
}
$event->timeout();
}, 1000000.0 * Daemon::$config->mpmdelay->value, 'MPM');
while (!$this->breakMainLoop) {
while (!$this->callbacks->isEmpty()) {
call_user_func($this->callbacks->shift(), $this);
}
event_base_loop($this->eventBase);
}
}
示例2: run
public function run()
{
proc_nice(Daemon::$settings['masterpriority']);
gc_enable();
register_shutdown_function(array($this, 'onShutdown'));
$this->collections = array('workers' => new threadCollection());
Thread::setproctitle(Daemon::$runName . ': master process' . (Daemon::$settings['pidfile'] !== Daemon::$settings['defaultpidfile'] ? ' (' . Daemon::$settings['pidfile'] . ')' : ''));
Daemon::$appResolver = (require Daemon::$settings['path']);
Daemon::$appResolver->preloadPrivileged();
$this->spawnWorkers(min(Daemon::$settings['startworkers'], Daemon::$settings['maxworkers']));
$mpmLast = time();
$autoReloadLast = time();
while (TRUE) {
pcntl_signal_dispatch();
$this->sigwait(1, 0);
clearstatcache();
if (Daemon::$logpointerpath !== Daemon::parseStoragepath(Daemon::$settings['logstorage'])) {
$this->sigusr1();
}
$c = 1;
if (time() > $mpmLast + Daemon::$parsedSettings['mpmdelay']) {
$mpmLast = time();
++$c;
if ($c > 0xfffff) {
$c = 0;
}
if ($c % 10 == 0) {
$this->collections['workers']->removeTerminated(TRUE);
gc_collect_cycles();
} else {
$this->collections['workers']->removeTerminated();
}
if (isset(Daemon::$settings['mpm']) && is_callable($c = Daemon::$settings['mpm'])) {
call_user_func($c);
} else {
$state = Daemon::getStateOfWorkers($this);
if ($state) {
$n = max(min(Daemon::$settings['minspareworkers'] - $state['idle'], Daemon::$settings['maxworkers'] - $state['alive']), Daemon::$settings['minworkers'] - $state['alive']);
if ($n > 0) {
Daemon::log('Spawning ' . $n . ' worker(s).');
$this->spawnWorkers($n);
}
$n = min($state['idle'] - Daemon::$settings['maxspareworkers'], $state['alive'] - Daemon::$settings['minworkers']);
if ($n > 0) {
Daemon::log('Stopping ' . $n . ' worker(s).');
$this->stopWorkers($n);
}
}
}
}
}
}
示例3: 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 Daemon::date_period_text(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
return;
}
示例4: run
/**
* Called when request iterated.
* @return integer Status.
*/
public function run()
{
$stime = microtime(TRUE);
$this->header('Content-Type: text/html');
$this->setcookie('testcookie', '1');
$this->registerShutdownFunction(function () {
?>
</html><?php
});
?>
<!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 />Counter of requests to this Application Instance: <b><?php
echo ++$this->appInstance->counter;
?>
</b>
<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 />Pool size: <?php
echo sizeof(Daemon::$process->pool);
?>
.
<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 = 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 />
<?php
}
?>
<br /><br />
<br /><br /><form action="<?php
echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES);
?>
" method="post" enctype="multipart/form-data">
<input type="file" name="myfile" />
<input type="submit" name="submit" value="Upload" />
</form>
<br />
<form action="<?php
echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES);
?>
//.........这里部分代码省略.........
示例5: init
//.........这里部分代码省略.........
$error = TRUE;
}
}
if (isset(Daemon::$config->user->value) && is_callable('posix_getuid')) {
if (($su = posix_getpwnam(Daemon::$config->user->value)) === FALSE) {
Daemon::log('Unexisting user \'' . Daemon::$config->user->value . '\', user not found. You have to replace config-variable \'user\' with existing username.');
$error = TRUE;
} elseif ($su['uid'] != posix_getuid() && posix_getuid() != 0) {
Daemon::log('You must have the root privileges to change user.');
$error = TRUE;
}
}
if (isset(Daemon::$config->minspareworkers->value) && isset(Daemon::$config->maxspareworkers->value)) {
if (Daemon::$config->minspareworkers->value > Daemon::$config->maxspareworkers->value) {
Daemon::log('\'minspareworkers\' cannot be greater than \'maxspareworkers\'.');
$error = TRUE;
}
}
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) {
Daemon_Bootstrap::start();
}
} elseif ($runmode == 'status' || $runmode == 'fullstatus') {
$status = Daemon_Bootstrap::$pid && posix_kill(Daemon_Bootstrap::$pid, SIGTTIN);
echo '[STATUS] phpDaemon ' . Daemon::$version . ' is ' . ($status ? 'running' : 'NOT running') . ' (' . Daemon::$config->pidfile->value . ").\n";
if ($status && $runmode == 'fullstatus') {
echo 'Uptime: ' . Daemon::date_period_text(filemtime(Daemon::$config->pidfile->value), time()) . "\n";
Daemon::$shm_wstate = Daemon::shmop_open(Daemon::$config->pidfile->value, 0, 'wstate', FALSE);
$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 "\tWait-init: " . $stat['waitinit'] . "\n";
echo "\tInit: " . $stat['init'] . "\n";
}
echo "\n";
} elseif ($runmode == 'update') {
if (!Daemon_Bootstrap::$pid || !posix_kill(Daemon_Bootstrap::$pid, SIGHUP)) {
echo '[UPDATE] ERROR. It seems that phpDaemon is not running' . (Daemon_Bootstrap::$pid ? ' (PID ' . Daemon_Bootstrap::$pid . ')' : '') . ".\n";
}
} elseif ($runmode == 'reopenlog') {
if (!Daemon_Bootstrap::$pid || !posix_kill(Daemon_Bootstrap::$pid, SIGUSR1)) {
echo '[REOPEN-LOG] ERROR. It seems that phpDaemon is not running' . (Daemon_Bootstrap::$pid ? ' (PID ' . Daemon_Bootstrap::$pid . ')' : '') . ".\n";
}
} elseif ($runmode == 'reload') {
if (!Daemon_Bootstrap::$pid || !posix_kill(Daemon_Bootstrap::$pid, SIGUSR2)) {
echo '[RELOAD] ERROR. It seems that phpDaemon is not running' . (Daemon_Bootstrap::$pid ? ' (PID ' . Daemon_Bootstrap::$pid . ')' : '') . ".\n";
}
} elseif ($runmode == 'restart') {
if ($error === FALSE) {
Daemon_Bootstrap::stop(2);
Daemon_Bootstrap::start();
}
} elseif ($runmode == 'hardrestart') {
Daemon_Bootstrap::stop(3);
Daemon_Bootstrap::start();
} elseif ($runmode == 'configtest') {
$term = new Terminal();
示例6: init
//.........这里部分代码省略.........
$error = TRUE;
}
}
if (isset(Daemon::$settings['user']) && is_callable('posix_getuid')) {
if (($su = posix_getpwnam(Daemon::$settings['user'])) === FALSE) {
Daemon::log('Unexisting user \'' . Daemon::$settings['user'] . '\', user not found. You have to replace config-variable \'user\' with existing username.');
$error = TRUE;
} elseif ($su['uid'] != posix_getuid() && posix_getuid() != 0) {
Daemon::log('You must have the root privileges to change user.');
$error = TRUE;
}
}
if (isset(Daemon::$settings['minspareworkers']) && isset(Daemon::$settings['maxspareworkers'])) {
if (Daemon::$settings['minspareworkers'] > Daemon::$settings['maxspareworkers']) {
Daemon::log('\'minspareworkers\' cannot be greater than \'maxspareworkers\'.');
$error = TRUE;
}
}
if (isset(Daemon::$settings['minworkers']) && isset(Daemon::$settings['maxworkers'])) {
if (Daemon::$settings['minworkers'] > Daemon::$settings['maxworkers']) {
Daemon::$settings['maxworkers'] = Daemon::$settings['minworkers'];
}
}
if ($runmode == 'start') {
if ($error === FALSE) {
Daemon_Bootstrap::start();
}
} elseif ($runmode == 'status' or $runmode == 'fullstatus') {
$status = Daemon_Bootstrap::$pid && posix_kill(Daemon_Bootstrap::$pid, SIGTTIN);
echo '[STATUS] phpDaemon ' . Daemon::$version . ' is ' . ($status ? 'running' : 'NOT running') . ' (' . Daemon_Bootstrap::$pidfile . ").\n";
if ($status && $runmode == 'fullstatus') {
echo 'Uptime: ' . Daemon::date_period_text(filemtime(Daemon_Bootstrap::$pidfile), time()) . "\n";
Daemon::$shm_wstate = Daemon::shmop_open(Daemon::$settings['ipcwstate'], 0, 'wstate', FALSE);
$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 "\tWait-init: " . $stat['waitinit'] . "\n";
echo "\tInit: " . $stat['init'] . "\n";
}
echo "\n";
} elseif ($runmode == 'update') {
if (!Daemon_Bootstrap::$pid || !posix_kill(Daemon_Bootstrap::$pid, SIGHUP)) {
echo '[UPDATE] ERROR. It seems that phpDaemon is not running' . (Daemon_Bootstrap::$pid ? ' (PID ' . Daemon_Bootstrap::$pid . ')' : '') . ".\n";
}
} elseif ($runmode == 'reopenlog') {
if (!Daemon_Bootstrap::$pid || !posix_kill(Daemon_Bootstrap::$pid, SIGUSR1)) {
echo '[REOPEN-LOG] ERROR. It seems that phpDaemon is not running' . (Daemon_Bootstrap::$pid ? ' (PID ' . Daemon_Bootstrap::$pid . ')' : '') . ".\n";
}
} elseif ($runmode == 'reload') {
if (!Daemon_Bootstrap::$pid || !posix_kill(Daemon_Bootstrap::$pid, SIGUSR2)) {
echo '[RELOAD] ERROR. It seems that phpDaemon is not running' . (Daemon_Bootstrap::$pid ? ' (PID ' . Daemon_Bootstrap::$pid . ')' : '') . ".\n";
}
} elseif ($runmode == 'restart') {
Daemon_Bootstrap::stop(2);
Daemon_Bootstrap::start();
} elseif ($runmode == 'hardrestart') {
Daemon_Bootstrap::stop(3);
Daemon_Bootstrap::start();
} elseif ($runmode == 'configtest') {
$term = new Terminal();
$term->enable_color = TRUE;
echo "\n";