当前位置: 首页>>代码示例>>PHP>>正文


PHP Thread::setproctitle方法代码示例

本文整理汇总了PHP中Thread::setproctitle方法的典型用法代码示例。如果您正苦于以下问题:PHP Thread::setproctitle方法的具体用法?PHP Thread::setproctitle怎么用?PHP Thread::setproctitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Thread的用法示例。


在下文中一共展示了Thread::setproctitle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
                     }
                 }
             }
         }
     }
 }
开发者ID:svcorp77,项目名称:phpdaemon,代码行数:52,代码来源:Daemon_MasterThread.class.php

示例2: run

 public function run()
 {
     proc_nice(Daemon::$settings['workerpriority']);
     Daemon::$worker = $this;
     $this->microsleep = Daemon::$settings['microsleep'];
     $this->autoReloadLast = time();
     $this->reloadDelay = Daemon::$parsedSettings['mpmdelay'] + 2;
     $this->setStatus(4);
     Thread::setproctitle(Daemon::$runName . ': worker process' . (Daemon::$settings['pidfile'] !== Daemon::$settings['defaultpidfile'] ? ' (' . Daemon::$settings['pidfile'] . ')' : ''));
     register_shutdown_function(array($this, 'shutdown'));
     if (Daemon::$settings['autogc'] > 0) {
         gc_enable();
     } else {
         gc_disable();
     }
     if (isset(Daemon::$settings['group'])) {
         $sg = posix_getgrnam(Daemon::$settings['group']);
     }
     if (isset(Daemon::$settings['user'])) {
         $su = posix_getpwnam(Daemon::$settings['user']);
     }
     if (Daemon::$settings['chroot'] !== '/') {
         if (posix_getuid() != 0) {
             Daemon::log('You must have the root privileges to change root.');
             exit(0);
         } elseif (!chroot(Daemon::$settings['chroot'])) {
             Daemon::log('Couldn\'t change root to \'' . Daemon::$settings['chroot'] . '\'.');
             exit(0);
         }
     }
     if (isset(Daemon::$settings['group'])) {
         if ($sg === FALSE) {
             Daemon::log('Couldn\'t change group to \'' . Daemon::$settings['group'] . '\'. You must replace config-variable \'group\' with existing group.');
             exit(0);
         } elseif ($sg['gid'] != posix_getgid() && !posix_setgid($sg['gid'])) {
             Daemon::log('Couldn\'t change group to \'' . Daemon::$settings['group'] . "'. Error (" . ($errno = posix_get_last_error()) . '): ' . posix_strerror($errno));
             exit(0);
         }
     }
     if (isset(Daemon::$settings['user'])) {
         if ($su === FALSE) {
             Daemon::log('Couldn\'t change user to \'' . Daemon::$settings['user'] . '\', user not found. You must replace config-variable \'user\' with existing username.');
             exit(0);
         } elseif ($su['uid'] != posix_getuid() && !posix_setuid($su['uid'])) {
             Daemon::log('Couldn\'t change user to \'' . Daemon::$settings['user'] . "'. Error (" . ($errno = posix_get_last_error()) . '): ' . posix_strerror($errno));
             exit(0);
         }
     }
     if (Daemon::$settings['cwd'] !== '.') {
         if (!@chdir(Daemon::$settings['cwd'])) {
             Daemon::log('WORKER ' . $this->pid . '] Couldn\'t change directory to \'' . Daemon::$settings['cwd'] . '.');
         }
     }
     $this->setStatus(6);
     $this->eventBase = event_base_new();
     Daemon::$appResolver->preload();
     foreach (Daemon::$appInstances as $app) {
         foreach ($app as $appInstance) {
             if (!$appInstance->ready) {
                 $this->ready = TRUE;
                 $appInstance->onReady();
             }
         }
     }
     $this->setStatus(1);
     $ev = event_new();
     event_set($ev, STDIN, EV_TIMEOUT, function () {
     }, array());
     event_base_set($ev, $this->eventBase);
     $this->timeoutEvent = $ev;
     while (TRUE) {
         pcntl_signal_dispatch();
         if (($s = $this->checkState()) !== TRUE) {
             $this->closeSockets();
             if (sizeof($this->queue) === 0) {
                 return $s;
             }
         }
         event_add($this->timeoutEvent, $this->microsleep);
         event_base_loop($this->eventBase, EVLOOP_ONCE);
         do {
             for ($i = 0, $s = sizeof($this->eventsToAdd); $i < $s; ++$i) {
                 event_add($this->eventsToAdd[$i]);
                 unset($this->eventsToAdd[$i]);
             }
             $this->readPool();
             $processed = $this->runQueue();
         } while ($processed || $this->readPoolState || $this->eventsToAdd);
     }
 }
开发者ID:svcorp77,项目名称:phpdaemon,代码行数:90,代码来源:Daemon_WorkerThread.class.php


注:本文中的Thread::setproctitle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。