當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。