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


PHP Daemon::runName方法代码示例

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


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

示例1: init

 public static function init()
 {
     Daemon::$eventBase = event_base_new();
     $args = $_SERVER['argv'];
     if (!isset($args[1]) || !isset($args[2])) {
         Terminal::drawStr('usage: php xxx.php sArea (start|stop|restart|reload|status)' . "\n");
         exit(-1);
     }
     // todo run multi app in one daemon.
     $sArea = $args[1];
     $command = $args[2];
     $appName = Config::get('socket_server_class', null, true);
     Daemon::$runName = $appName;
     $runAppInstance = array($appName => $appName);
     if ($command == 'start') {
         // fork later
         self::$pid = posix_getpid();
         Debug::log('start');
         foreach ($runAppInstance as $appName) {
             $obj = new $appName();
         }
         while (!Daemon::$breakEventLoop) {
             event_base_loop(daemon::$eventBase, EVLOOP_ONCE);
             // 清空本次写状态数组
             gc_collect_cycles();
             //daemon::debug('<== evet_base_loop() ending');
         }
     } elseif ($command == 'stop') {
         // cat pid, stop
     } elseif ($command == 'status') {
         // cat pid, show status
     } elseif ($command == 'restart') {
         //self::stop();
         //self::start();
     }
 }
开发者ID:ansendu,项目名称:ansio,代码行数:36,代码来源:Daemon.php

示例2: init

 /**
  * Actions on early startup.
  * @return void
  */
 public static function init()
 {
     Daemon::initSettings();
     Daemon::$runName = basename($_SERVER['argv'][0]);
     $error = FALSE;
     $argv = $_SERVER['argv'];
     $runmode = isset($argv[1]) ? str_replace('-', '', $argv[1]) : '';
     $args = Daemon_Bootstrap::getArgs($argv);
     if (!isset(self::$params[$runmode]) && !in_array($runmode, self::$commands)) {
         if ('' !== $runmode) {
             echo 'Unrecognized command: ' . $runmode . "\n";
         }
         self::printUsage();
         exit;
     } elseif ('help' === $runmode) {
         self::printHelp();
         exit;
     }
     if (isset($args['configfile'])) {
         Daemon::$config->configfile->setHumanValue($args['configfile']);
     }
     if (!Daemon::$config->loadCmdLineArgs($args)) {
         $error = TRUE;
     }
     if (!Daemon::loadConfig(Daemon::$config->configfile->value)) {
         $error = TRUE;
     }
     if (version_compare(PHP_VERSION, '5.3.0', '>=') === 1) {
         Daemon::log('PHP >= 5.3.0 required.');
         $error = TRUE;
     }
     if (!Daemon::$useSockets) {
         Daemon::log('Cannot use socket extension, using stream_* instead. Non-critical error, but the performance compromised.');
     }
     if (isset(Daemon::$config->locale->value) && Daemon::$config->locale->value !== '') {
         setlocale(LC_ALL, explode(',', Daemon::$config->locale->value));
     }
     if (Daemon::$config->autoreimport->value && !is_callable('runkit_import')) {
         Daemon::log('runkit extension not found. You should install it or disable --auto-reimport.');
         $error = TRUE;
     }
     if (!is_callable('posix_kill')) {
         Daemon::log('Posix not found. You should compile PHP without \'--disable-posix\'.');
         $error = TRUE;
     }
     if (!is_callable('pcntl_signal')) {
         Daemon::log('PCNTL not found. You should compile PHP with \'--enable-pcntl\'.');
         $error = TRUE;
     }
     if (!is_callable('event_base_new')) {
         Daemon::log('libevent extension not found. You have to install libevent from pecl (http://pecl.php.net/package/libevent). `svn checkout http://svn.php.net/repository/pecl/libevent pecl-libevent`.');
         $error = TRUE;
     }
     if (!is_callable('socket_create')) {
         Daemon::log('Sockets extension not found. You should compile PHP with \'--enable-sockets\'.');
         $error = TRUE;
     }
     if (!is_callable('shmop_open')) {
         Daemon::log('Shmop extension not found. You should compile PHP with \'--enable-shmop\'.');
         $error = TRUE;
     }
     if (!isset(Daemon::$config->user)) {
         Daemon::log('You must set \'user\' parameter.');
         $error = TRUE;
     }
     if (!isset(Daemon::$config->path)) {
         Daemon::log('You must set \'path\' parameter (path to your application resolver).');
         $error = TRUE;
     }
     if (!file_exists(Daemon::$config->pidfile->value)) {
         if (!touch(Daemon::$config->pidfile->value)) {
             Daemon::log('Couldn\'t create pid-file \'' . Daemon::$config->pidfile->value . '\'.');
             $error = TRUE;
         }
         Daemon_Bootstrap::$pid = 0;
     } elseif (!is_file(Daemon::$config->pidfile->value)) {
         Daemon::log('Pid-file \'' . Daemon::$config->pidfile->value . '\' must be a regular file.');
         Daemon_Bootstrap::$pid = FALSE;
         $error = TRUE;
     } elseif (!is_writable(Daemon::$config->pidfile->value)) {
         Daemon::log('Pid-file \'' . Daemon::$config->pidfile->value . '\' must be writable.');
         $error = TRUE;
     } elseif (!is_readable(Daemon::$config->pidfile->value)) {
         Daemon::log('Pid-file \'' . Daemon::$config->pidfile->value . '\' must be readable.');
         Daemon_Bootstrap::$pid = FALSE;
         $error = TRUE;
     } else {
         Daemon_Bootstrap::$pid = (int) file_get_contents(Daemon::$config->pidfile->value);
     }
     if (Daemon::$config->chroot->value !== '/') {
         if (posix_getuid() != 0) {
             Daemon::log('You must have the root privileges to change root.');
             $error = TRUE;
         }
     }
     if (!@is_file(Daemon::$config->path->value)) {
//.........这里部分代码省略.........
开发者ID:J3FF3,项目名称:phpdaemon,代码行数:101,代码来源:Daemon_Bootstrap.php

示例3: init

 public static function init()
 {
     Daemon::initSettings();
     Daemon::$runName = basename($_SERVER['argv'][0]);
     $error = FALSE;
     $argv = $_SERVER['argv'];
     $runmode = isset($argv[1]) ? str_replace('-', '', $argv[1]) : '';
     $args = Daemon_Bootstrap::getArgs($argv);
     if (isset($args[$k = 'configfile'])) {
         Daemon::$settings[$k] = $args[$k];
     }
     if (isset(Daemon::$settings['configfile']) && !Daemon::loadConfig(Daemon::$settings['configfile'])) {
         $error = TRUE;
     }
     if (!Daemon::loadSettings($args)) {
         $error = TRUE;
     }
     if (version_compare(PHP_VERSION, '5.3.0', '>=') === 1) {
         Daemon::log('PHP >= 5.3.0 required.');
         $error = TRUE;
     }
     if (isset(Daemon::$settings['locale'])) {
         setlocale(LC_ALL, explode(',', Daemon::$settings['locale']));
     }
     if (!is_callable('posix_kill')) {
         Daemon::log('Posix not found. You should compile PHP without \'--disable-posix\'.');
         $error = TRUE;
     }
     if (!is_callable('pcntl_signal')) {
         Daemon::log('PCNTL not found. You should compile PHP with \'--enable-pcntl\'.');
         $error = TRUE;
     }
     if (!is_callable('event_base_new')) {
         Daemon::log('libevent extension not found. You have to install libevent from pecl (http://pecl.php.net/package/libevent). `svn checkout http://svn.php.net/repository/pecl/libevent pecl-libevent`.');
         $error = TRUE;
     }
     if (!is_callable('socket_create')) {
         Daemon::log('Sockets extension not found. You should compile PHP with \'--enable-sockets\'.');
         $error = TRUE;
     }
     if (!is_callable('shmop_open')) {
         Daemon::log('Shmop extension not found. You should compile PHP with \'--enable-shmop\'.');
         $error = TRUE;
     }
     if (!isset(Daemon::$settings['user'])) {
         Daemon::log('You must set \'user\' parameter.');
         $error = TRUE;
     }
     if (!isset(Daemon::$settings['path'])) {
         Daemon::log('You must set \'path\' parameter (path to your application resolver).');
         $error = TRUE;
     }
     Daemon_Bootstrap::$pidfile = realpath(Daemon::$settings['pidfile']);
     if (!Daemon_Bootstrap::$pidfile) {
         Daemon_Bootstrap::$pidfile = Daemon::$settings['pidfile'];
     }
     if (!file_exists(Daemon_Bootstrap::$pidfile)) {
         if (!touch(Daemon_Bootstrap::$pidfile)) {
             Daemon::log('Couldn\'t create pid-file \'' . Daemon_Bootstrap::$pidfile . '\'.');
             $error = TRUE;
         }
         Daemon_Bootstrap::$pid = 0;
     } elseif (!is_file(Daemon_Bootstrap::$pidfile)) {
         Daemon::log('Pid-file \'' . Daemon_Bootstrap::$pidfile . '\' must be a regular file.');
         Daemon_Bootstrap::$pid = FALSE;
         $error = TRUE;
     } elseif (!is_writable(Daemon_Bootstrap::$pidfile)) {
         Daemon::log('Pid-file \'' . Daemon_Bootstrap::$pidfile . '\' must be writable.');
         $error = TRUE;
     } elseif (!is_readable(Daemon_Bootstrap::$pidfile)) {
         Daemon::log('Pid-file \'' . Daemon_Bootstrap::$pidfile . '\' must be readable.');
         Daemon_Bootstrap::$pid = FALSE;
         $error = TRUE;
     } else {
         Daemon_Bootstrap::$pid = (int) file_get_contents(Daemon_Bootstrap::$pidfile);
     }
     if (Daemon::$settings['chroot'] !== '/') {
         if (posix_getuid() != 0) {
             Daemon::log('You must have the root privileges to change root.');
             $error = TRUE;
         }
     }
     if (!@is_file(Daemon::$pathReal)) {
         Daemon::log('Your application resolver \'' . Daemon::$settings['path'] . '\' is not available.');
         $error = TRUE;
     }
     if (isset(Daemon::$settings['group']) && is_callable('posix_getgid')) {
         if (($sg = posix_getgrnam(Daemon::$settings['group'])) === FALSE) {
             Daemon::log('Unexisting group \'' . Daemon::$settings['group'] . '\'. You have to replace config-variable \'group\' with existing group-name.');
             $error = TRUE;
         } elseif ($sg['gid'] != posix_getgid() && posix_getuid() != 0) {
             Daemon::log('You must have the root privileges to change group.');
             $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) {
//.........这里部分代码省略.........
开发者ID:svcorp77,项目名称:phpdaemon,代码行数:101,代码来源:Daemon_Bootstrap.class.php


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