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


PHP posix_getppid函数代码示例

本文整理汇总了PHP中posix_getppid函数的典型用法代码示例。如果您正苦于以下问题:PHP posix_getppid函数的具体用法?PHP posix_getppid怎么用?PHP posix_getppid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: __construct

 /**
  * Constructor.
  *
  * @param Master  $master The master object
  * @param integer $pid    The child process id or null if this is the child
  *
  * @throws \Exception
  * @throws \RuntimeException
  */
 public function __construct(Master $master, $pid = null)
 {
     $this->master = $master;
     $directions = array('up', 'down');
     if (null === $pid) {
         // child
         $pid = posix_getpid();
         $pPid = posix_getppid();
         $modes = array('write', 'read');
     } else {
         // parent
         $pPid = null;
         $modes = array('read', 'write');
     }
     $this->pid = $pid;
     $this->ppid = $pPid;
     foreach (array_combine($directions, $modes) as $direction => $mode) {
         $fifo = $this->getPath($direction);
         if (!file_exists($fifo) && !posix_mkfifo($fifo, 0600) && 17 !== ($error = posix_get_last_error())) {
             throw new \Exception(sprintf('Error while creating FIFO: %s (%d)', posix_strerror($error), $error));
         }
         $this->{$mode} = fopen($fifo, $mode[0]);
         if (false === ($this->{$mode} = fopen($fifo, $mode[0]))) {
             throw new \RuntimeException(sprintf('Unable to open %s FIFO.', $mode));
         }
     }
 }
开发者ID:gcds,项目名称:morker,代码行数:36,代码来源:Fifo.php

示例2: start

 /**
  * 进程启动
  */
 public function start()
 {
     // 安装信号处理函数
     $this->installSignal();
     // 添加accept事件
     $ret = $this->event->add($this->mainSocket, Man\Core\Events\BaseEvent::EV_READ, array($this, 'accept'));
     // 创建内部通信套接字
     $start_port = Man\Core\Lib\Config::get($this->workerName . '.lan_port_start');
     $this->lanPort = $start_port - posix_getppid() + posix_getpid();
     $this->lanIp = Man\Core\Lib\Config::get($this->workerName . '.lan_ip');
     if (!$this->lanIp) {
         $this->notice($this->workerName . '.lan_ip not set');
         $this->lanIp = '127.0.0.1';
     }
     $error_no = 0;
     $error_msg = '';
     $this->innerMainSocket = stream_socket_server("udp://" . $this->lanIp . ':' . $this->lanPort, $error_no, $error_msg, STREAM_SERVER_BIND);
     if (!$this->innerMainSocket) {
         $this->notice('create innerMainSocket fail and exit ' . $error_no . ':' . $error_msg);
         sleep(1);
         exit(0);
     } else {
         stream_set_blocking($this->innerMainSocket, 0);
     }
     $this->registerAddress("udp://" . $this->lanIp . ':' . $this->lanPort);
     // 添加读udp事件
     $this->event->add($this->innerMainSocket, Man\Core\Events\BaseEvent::EV_READ, array($this, 'recvUdp'));
     // 初始化到worker的通信地址
     $this->initWorkerAddresses();
     // 主体循环,整个子进程会阻塞在这个函数上
     $ret = $this->event->loop();
     $this->notice('worker loop exit');
     exit(0);
 }
开发者ID:bennysuh,项目名称:workerman-game,代码行数:37,代码来源:GameGateway.php

示例3: init

 public static function init()
 {
     self::$pid = \posix_getpid();
     self::$ppid = \posix_getppid();
     self::$child = array();
     self::$alias = array();
     self::$user_events = array();
     self::$shm_to_pid = array();
     self::$status['start_time'] = time();
     // self::$shm_to_parent = -1;
     if (!self::$do_once) {
         // 初始化事件对象
         if (extension_loaded('libevent')) {
             self::$events = new Libevent();
         } else {
             self::$events = new Select();
         }
         self::$shm = new Shm(__FILE__, 'a');
         // 注册用户信号SIGUSR1处理函数
         self::onSysEvent(SIGUSR1, EventInterface::EV_SIGNAL, array("\\cli\\proc\\Process", 'defaultSigusr1Cbk'));
         // 注册子进程退出处理函数
         self::onSysEvent(SIGCHLD, EventInterface::EV_SIGNAL, array("\\cli\\proc\\Process", 'defaultSigchldCbk'));
         // 注册用户信号SIGUSR2处理函数
         self::onSysEvent(SIGUSR2, EventInterface::EV_SIGNAL, array("\\cli\\proc\\Process", 'defaultSigusr2Cbk'));
         // 注册exit回调函数
         register_shutdown_function(function () {
             Process::closeShm();
         });
         self::$do_once = true;
     }
 }
开发者ID:hduwzy,项目名称:test,代码行数:31,代码来源:Process.php

示例4: __construct

 /**
  * Constructor.
  *
  * @param resource $fileStream      File stream
  * @param string   $messageTemplate Message template.
  * @param array    $replacements    Replacements for template
  */
 public function __construct($fileStream, $messageTemplate = null, array $replacements = [])
 {
     if (empty($replacements)) {
         $replacements = array('{date}' => date('Y-m-d H:i:s'), '{message}' => null, '{pid}' => posix_getpid(), '{ppid}' => posix_getppid());
     }
     $this->messageTemplate = $messageTemplate;
     $this->fileStream = $fileStream;
     $this->replacements = $replacements;
 }
开发者ID:almadomundo,项目名称:php-daemonize,代码行数:16,代码来源:File.php

示例5: checkExit

 private function checkExit()
 {
     $ppid = posix_getppid();
     if ($this->ppid == 0) {
         $this->ppid = $ppid;
     }
     if ($this->ppid != $ppid) {
         $this->_exit();
     }
 }
开发者ID:mawenpei,项目名称:swoole-crontab,代码行数:10,代码来源:BaseWorker.php

示例6: shutdown

 /**
  * завершение работы
  */
 public function shutdown()
 {
     try {
         $this->onShutdown();
         static::log(getmypid() . ' is getting shutdown', Logger::L_DEBUG);
         static::log('Parent PID - ' . posix_getppid(), Logger::L_TRACE);
         parent::shutdown();
     } catch (\Exception $e) {
         exit(1);
     }
 }
开发者ID:yutas,项目名称:phpdaemon,代码行数:14,代码来源:Child.php

示例7: stillWorking

 public final function stillWorking()
 {
     if (!posix_isatty(STDOUT)) {
         posix_kill(posix_getppid(), SIGUSR1);
     }
     if ($this->traceMemory) {
         $memuse = number_format(memory_get_usage() / 1024, 1);
         $daemon = get_class($this);
         fprintf(STDERR, '%s', "<RAMS> {$daemon} Memory Usage: {$memuse} KB\n");
     }
 }
开发者ID:lsubra,项目名称:libphutil,代码行数:11,代码来源:PhutilDaemon.php

示例8: testSiteSet

 function testSiteSet()
 {
     if ($this->is_windows()) {
         $this->markTestSkipped('Site-set not currently available on Windows.');
     }
     $tmp_path = UNISH_TMP;
     putenv("TMPDIR={$tmp_path}");
     $posix_pid = posix_getppid();
     $expected_file = UNISH_TMP . '/drush-env/drush-drupal-site-' . $posix_pid;
     $filename = drush_sitealias_get_envar_filename();
     $this->assertEquals($expected_file, $filename);
 }
开发者ID:AndBicScadMedia,项目名称:drush-ops.github.com,代码行数:12,代码来源:siteSetUnitTest.php

示例9: waitChild

 protected function waitChild()
 {
     if (!$this->pid) {
         $file = sys_get_temp_dir() . '/parallel' . posix_getppid() . '.sock';
         $address = 'unix://' . $file;
         $result = $this->run();
         if ($client = stream_socket_client($address)) {
             stream_socket_sendto($client, serialize([posix_getpid(), $result]));
             fclose($client);
         }
         posix_kill(posix_getpid(), SIGHUP);
         return;
     }
 }
开发者ID:tiagobutzke,项目名称:phparallel,代码行数:14,代码来源:SharedThread.php

示例10: getParent

 /**
  *
  * @return Comos\Qpm\Process\Process returns null on failure
  *         It cannot be realtime in some cases.
  *         e.g.
  *         $child = Process::current()->folkByCallable($fun);
  *         echo $child->getParent()->getPid();
  *         If child process changed the parent, you would get the old parent ID.
  */
 public function getParent()
 {
     if ($this->_parentProcessId) {
         return self::process($this->_parentProcessId);
     }
     if ($this->isCurrent()) {
         $ppid = \posix_getppid();
         if (!$ppid) {
             return null;
         }
         return self::process($ppid);
     }
     return null;
 }
开发者ID:jinchunguang,项目名称:qpm,代码行数:23,代码来源:Process.php

示例11: __construct

 /**
  * Constructor.
  *
  * @param integer $pid    The child process id or null if this is the child
  * @param integer $signal The signal to send after writing to shared memory
  */
 public function __construct($pid = null, $signal = null)
 {
     if (null === $pid) {
         // child
         $pid = posix_getpid();
         $ppid = posix_getppid();
     } else {
         // parent
         $ppid = null;
     }
     $this->pid = $pid;
     $this->ppid = $ppid;
     $this->signal = $signal;
 }
开发者ID:edwardstock,项目名称:spork,代码行数:20,代码来源:SharedMemory.php

示例12: buildProd

 public static function buildProd($dump = null)
 {
     $dump = $dump ?: rtrim(sys_get_temp_dir(), "/") . "/" . posix_getppid();
     $storage = CodeStorage::create($dump);
     if (extension_loaded("apc")) {
         $cache = new ApcCache("Spot");
     } else {
         if (extension_loaded("xcache")) {
             $cache = new XcacheCache();
         } else {
             $cache = new PhpFileCache($dump);
         }
     }
     return new Spot(Spot::PROD_MODE, $dump, $cache, $storage);
 }
开发者ID:spotframework,项目名称:spot,代码行数:15,代码来源:Spot.php

示例13: fork

 function fork()
 {
     $pid = pcntl_fork();
     if ($pid == -1) {
         throw new Exception('fork error on Task object');
     } elseif ($pid) {
         // we are in the parent class
         $this->pid = $pid;
         // echo "< in parent with pid {$this->pid}\n";
     } else {
         // we are in the child ᶘ ᵒᴥᵒᶅ
         $this->ppid = posix_getppid();
         $this->pid = posix_getpid();
         $this->run();
         exit(0);
     }
 }
开发者ID:atlantis3001,项目名称:nofussframework,代码行数:17,代码来源:Task.php

示例14: init

 public function init()
 {
     $pid = pcntl_fork();
     if ($pid == -1) {
         //Return message for the
         //echo json_encode(array('ERROR' => 1, 'MESSAGE' => 'CANNOT FORK, check php configuration', 'CODE_ERROR' => ERROR_FORK));
         exit(1);
     } elseif ($pid) {
         //echo json_encode(array('PID' => $pid, 'ERROR' => 0, 'MESSAGE' => 'Running tasks...', 'PROGRESS' => 0));
         exit(0);
     } else {
         //Daemonize the element
         $this->father_pid = posix_getppid();
         $sid = posix_setsid();
         $this->pid = getmypid();
         echo $this->father_pid;
         $this->log(array('ERROR' => 0, 'MESSAGE' => 'Running daemon...', 'PROGRESS' => 0));
     }
 }
开发者ID:phangoapp,项目名称:phasys,代码行数:19,代码来源:Daemon.php

示例15: forkChild

 public function forkChild($callback, $data)
 {
     $pid = pcntl_fork();
     switch ($pid) {
         case 0:
             // Child process
             $this->isChild = true;
             call_user_func_array($callback, $data);
             posix_kill(posix_getppid(), SIGCHLD);
             exit;
         case -1:
             // Parent process, fork failed
             throw new \Exception("Out of memory!");
         default:
             // Parent process, fork succeeded
             $this->processes[$pid] = true;
             return $pid;
     }
 }
开发者ID:nousefreak,项目名称:nousetools,代码行数:19,代码来源:ProcessManager.php


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