• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP posix_getppid函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: check_files_change

function check_files_change($monitor_dir)
{
    // 递归遍历目录
    $dir_iterator = new RecursiveDirectoryIterator($monitor_dir);
    $iterator = new RecursiveIteratorIterator($dir_iterator);
    $time_now = time();
    foreach ($iterator as $file) {
        // 只监控php文件
        if (pathinfo($file, PATHINFO_EXTENSION) != 'php') {
            continue;
        }
        // 在最近1秒内有修改
        if ($time_now - $file->getMTime() == 1) {
            echo $file . " update and reload\n";
            // 给父进程发送reload信号
            posix_kill(posix_getppid(), SIGUSR1);
        }
    }
}
开发者ID:songsihan,项目名称:doudizhu,代码行数:19,代码来源:start.php


示例17: check_files_change

function check_files_change($inotify_fd)
{
    global $monitor_files;
    // 读取有哪些文件事件
    $events = inotify_read($inotify_fd);
    if ($events) {
        // 检查哪些文件被更新了
        foreach ($events as $ev) {
            // 更新的文件
            $file = $monitor_files[$ev['wd']];
            echo $file . " update and reload\n";
            unset($monitor_files[$ev['wd']]);
            // 需要把文件重新加入监控
            $wd = inotify_add_watch($inotify_fd, $file, IN_MODIFY);
            $monitor_files[$wd] = $file;
        }
        // 给父进程也就是主进程发送reload信号
        posix_kill(posix_getppid(), SIGUSR1);
    }
}
开发者ID:shitfSign,项目名称:workerman-filemonitor-inotify,代码行数:20,代码来源:start.php


示例18: run

 function run($work)
 {
     if (1 === posix_getppid()) {
         return;
     }
     if ($this->user) {
         if (!posix_setgid($this->user['gid']) || !posix_setuid($this->user['uid'])) {
             throw new \RuntimeException("Unable to switch to user '{$this->user['name']}'");
         }
     }
     Utility::fork(function () use($work) {
         if (-1 === posix_setsid()) {
             throw new \RuntimeException('Unable to set setsid()');
         }
         if (false === chdir('/')) {
             throw new \RuntimeException('Unable to chdir(\'/\')');
         }
         umask(0);
         Utility::fork($work);
     });
 }
开发者ID:JaredWilliams,项目名称:PHPGearmanToolkit,代码行数:21,代码来源:ProcessControl.php


示例19: kill

 public static function kill()
 {
     $rets = $match = array();
     $process_lists = [isset(self::$serverConfig['server']['master_process_name']) ? self::$serverConfig['server']['master_process_name'] : 'ypf:swoole-master', isset(self::$serverConfig['server']['worker_process_name']) ? self::$serverConfig['server']['worker_process_name'] : 'ypf:swoole-worker-%d', isset(self::$serverConfig['server']['task_worker_process_name']) ? self::$serverConfig['server']['task_worker_process_name'] : 'ypf:swoole-task-worker-%d', isset(self::$serverConfig['server']['cron_worker_process_name']) ? self::$serverConfig['server']['cron_worker_process_name'] : 'ypf:swoole-cron-worker'];
     foreach ($process_lists as $i => $process_name) {
         $process_name = str_replace("%d", "", $process_name);
         exec("ps aux | grep -E '" . $process_name . "' | grep -v grep", $rets[$i]);
     }
     $this_pid = posix_getpid();
     $this_ppid = posix_getppid();
     foreach ($rets as $ret) {
         foreach ($ret as $line) {
             if (preg_match("/^[\\S]+\\s+(\\d+)\\s+/", $line, $match)) {
                 $tmp_pid = $match[1];
                 if ($this_pid != $tmp_pid && $this_ppid != $tmp_pid) {
                     posix_kill($tmp_pid, 9);
                 }
             }
         }
     }
     exit("server killed ..." . PHP_EOL);
 }
开发者ID:millken,项目名称:ypf,代码行数:22,代码来源:Cmd.php


示例20: forked

 /**
  * @param string $instance
  * @return void
  */
 public function forked(string $instance = 'child')
 {
     $this->pid = posix_getpid();
     $this->parentPid = posix_getppid();
     $this->setInstanceName($instance);
 }
开发者ID:sgc-fireball,项目名称:libphp,代码行数:10,代码来源:Daemon.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP posix_getpwnam函数代码示例发布时间:2022-05-15
下一篇:
PHP posix_getpid函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap