當前位置: 首頁>>代碼示例>>PHP>>正文


PHP swoole_process::wait方法代碼示例

本文整理匯總了PHP中swoole_process::wait方法的典型用法代碼示例。如果您正苦於以下問題:PHP swoole_process::wait方法的具體用法?PHP swoole_process::wait怎麽用?PHP swoole_process::wait使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在swoole_process的用法示例。


在下文中一共展示了swoole_process::wait方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: master_process

function master_process($workers)
{
    //監聽子進程,如果停止,會再拉起來
    swoole_process::signal(SIGCHLD, function ($signo) use(&$workers) {
        while (1) {
            $ret = swoole_process::wait(false);
            if ($ret) {
                $pid = $ret['pid'];
                //這裏實現一個自動拉起的能力
                $child_process = $workers[$pid];
                logprint('info', "Worker Exit, kill_signal={$ret['signal']} PID=" . $pid);
                $new_pid = $child_process->start();
                $workers[$new_pid] = $child_process;
                unset($workers[$pid]);
            } else {
                break;
            }
        }
    });
    //kill -10 結束全部程序
    swoole_process::signal(SIGUSR1, function ($signo) use(&$workers) {
        swoole_process::signal(SIGCHLD, null);
        foreach ($workers as $pid => $worker) {
            swoole_process::kill($pid);
        }
        //處理子進程,然後自己退出
        exit;
    });
}
開發者ID:peterxiemin,項目名稱:commonswoole,代碼行數:29,代碼來源:timer.php

示例2: registerSignal

 /**
  * 注冊信號
  */
 public static function registerSignal()
 {
     //終止進程
     \swoole_process::signal(SIGTERM, function ($signo) {
         self::exit2p('master process [' . self::$process_name . '] exit');
     });
     //忽略信號,當子進程停止或退出時通知父進程
     \swoole_process::signal(SIGCHLD, function ($signo) {
         //非阻塞等待
         while ($ret = \swoole_process::wait(false)) {
             $pid = $ret['pid'];
             if (isset(self::$worker_list[$pid])) {
                 $worker = self::$worker_list[$pid];
                 $worker['process']->close();
                 //重啟該子進程
                 self::createWorkerProcess($worker['className'], $worker['number'], $worker['options']);
                 defined('PHPKIT_RUN_DEBUG') && syslog(LOG_INFO, 'child process restart:' . $pid);
             }
         }
     });
     //終止進程,用戶定義信號1
     \swoole_process::signal(SIGUSR1, function ($signo) {
         //TODO something
     });
     defined('PHPKIT_RUN_DEBUG') && syslog(LOG_INFO, 'register signal success');
 }
開發者ID:mawenpei,項目名稱:swoole-crontab,代碼行數:29,代碼來源:Handler.php

示例3: run

 function run($options)
 {
     $asDaemon = isset($options['asDaemon']) ? $options['asDaemon'] : 0;
     if ($asDaemon) {
         \swoole_process::daemon();
     }
     $pids = [];
     $workers = [];
     for ($i = 0; $i < $this->worker_num; $i++) {
         $process = new \swoole_process($this->workerStart, $this->redirect_stdout);
         $process->id = $i;
         $pid = $process->start();
         $pids[] = $pid;
         $workers[$pid] = $process;
     }
     $pidFile = isset($options['pidFile']) ? $options['pidFile'] : 0;
     if ($pidFile) {
         $ppid = posix_getpid();
         $pids[] = $ppid;
         file_put_contents($pidFile, implode("|", $pids));
     }
     \swoole_process::signal(SIGTERM, function () use($workers) {
         exit(0);
     });
     \swoole_process::signal(SIGINT, function () {
         exit(0);
     });
     \swoole_process::wait(false);
     return $workers;
 }
開發者ID:kerisy,項目名稱:framework,代碼行數:30,代碼來源:Process.php

示例4: master_async

function master_async($workers)
{
    swoole_process::signal(SIGCHLD, function ($signo) use(&$workers) {
        while (1) {
            $ret = swoole_process::wait(false);
            if ($ret) {
                $pid = $ret['pid'];
                $child_process = $workers[$pid];
                //unset($workers[$pid]);
                echo "Worker Exit, kill_signal={$ret['signal']} PID=" . $pid . PHP_EOL;
                $new_pid = $child_process->start();
                $workers[$new_pid] = $child_process;
                unset($workers[$pid]);
            } else {
                break;
            }
        }
    });
    /**
     * @var $process swoole_process
     */
    foreach ($workers as $pid => $process) {
        swoole_event_add($process->pipe, function ($pipe) use($process) {
            $recv = $process->read();
            if ($recv) {
                echo "From Worker: " . $recv;
            }
            $process->write("HELLO worker {$process->pid}\n");
        });
        $process->write("hello worker[{$pid}]\n");
    }
}
開發者ID:zzjin,項目名稱:swoole-src,代碼行數:32,代碼來源:worker.php

示例5: master_async

function master_async($workers)
{
    swoole_process::signal(SIGCHLD, function ($signo) use($workers) {
        while (1) {
            $ret = swoole_process::wait(false);
            if ($ret) {
                $pid = $ret['pid'];
                unset($workers[$pid]);
                echo "Worker Exit, PID=" . $pid . PHP_EOL;
            } else {
                break;
            }
        }
    });
    /**
     * @var $process swoole_process
     */
    foreach ($workers as $pid => $process) {
        swoole_event_add($process->pipe, function ($pipe) use($process) {
            $recv = $process->read();
            if ($recv) {
                echo "From Worker: " . $recv;
            }
        });
        $process->write("hello worker[{$pid}]\n");
    }
}
開發者ID:sophia2152,項目名稱:swoole-src,代碼行數:27,代碼來源:worker.php

示例6: run

 static function run()
 {
     $table = new swoole_table(1024 * 256);
     $table->column('index', swoole_table::TYPE_INT);
     $table->column('serid', swoole_table::TYPE_INT);
     $table->column('data', swoole_table::TYPE_STRING, 64);
     $table->create();
     self::$table = $table;
     for ($i = 0; $i < self::$key_num; $i++) {
         $key = 'user_' . (self::$key_base + $i);
         $ret = self::$table->set($key, array('index' => $i, 'serid' => rand(1000, 9999), 'data' => "hello_world_{$i}"));
         if (!$ret) {
             echo "count {$i} failed.";
             break;
         }
     }
     for ($i = 0; $i < self::$worker_num; $i++) {
         $process = new swoole_process('UnitTest_Table::worker');
         $process->start();
         $workers[$i] = $process;
     }
     for ($i = 0; $i < self::$worker_num; $i++) {
         $exit = swoole_process::wait();
         echo "worker[{$i}] exit\n";
     }
 }
開發者ID:cjq,項目名稱:tests,代碼行數:26,代碼來源:table.php

示例7: onWorkerStart

 public function onWorkerStart(swoole_server $server, $worker_id)
 {
     swoole_process::signal(SIGCHLD, function ($sig) {
         //必須為false,非阻塞模式
         while ($ret = swoole_process::wait(false)) {
             echo "PID={$ret['pid']}\n";
         }
     });
 }
開發者ID:jinchunguang,項目名稱:swoole-doc,代碼行數:9,代碼來源:shell_server.php

示例8: master_run

 private function master_run()
 {
     $event = event_new();
     event_set($event, $this->socket_fd, EV_READ | EV_PERSIST, array($this, 'dispatch'));
     event_base_set($event, $this->event_base);
     event_add($event);
     event_base_loop($this->event_base);
     swoole_process::wait();
 }
開發者ID:zhangjingpu,項目名稱:yaf-lib,代碼行數:9,代碼來源:Processpool.php

示例9: master_async

 function master_async()
 {
     $count = 0;
     swoole_process::signal(SIGCHLD, function ($signo) use(&$count) {
         while (1) {
             $ret = swoole_process::wait(false);
             if ($ret) {
                 $pid = $ret['pid'];
                 $count++;
                 //echo "Worker Exit, kill_signal={$ret['signal']} PID=" . $pid . PHP_EOL;
                 //echo "Count=" . $count . " Worker_num=" . $this->worker_num . " Stauts=" . $this->status . PHP_EOL;
                 if ($count == $this->worker_num) {
                     switch ($this->status) {
                         case '3-dim':
                             $this->report_cost();
                             exit(0);
                             break;
                         case 'import':
                             $this->report_cost();
                             $this->status = '1-dim';
                             $this->restart_process();
                             break;
                         case '1-dim':
                             $this->report_cost();
                             $this->status = '2-dim';
                             $this->restart_process();
                             break;
                         case '2-dim':
                             $this->report_cost();
                             $this->status = '3-dim';
                             $this->restart_process();
                             break;
                         default:
                             break;
                     }
                     $count = 0;
                 }
             } else {
                 break;
             }
         }
     });
     /**
      * @var $process swoole_process
      */
     foreach ($this->workers as $pid => $process) {
         swoole_event_add($process->pipe, function ($pipe) use($process) {
             $recv = $process->read();
             if ($recv) {
                 echo "From Worker: " . $recv;
             }
             $process->write("HELLO worker {$process->pid}\n");
         });
         $process->write("hello worker[{$pid}]\n");
     }
 }
開發者ID:shenxinyu,項目名稱:redis_rank,代碼行數:56,代碼來源:paralle_rank.php

示例10: callback_timer_function

function callback_timer_function()
{
    $Handle = new TimingCall_Tasks();
    $Handle->upDaemonTime();
    $tasks = $Handle->readExecuteTasks();
    foreach ($tasks as $task) {
        $process = new swoole_process('callback_process_function', true);
        $process->write(json_encode($task));
        $process->start();
        $process->wait(false);
    }
}
開發者ID:imdaqian,項目名稱:Hi-Timed,代碼行數:12,代碼來源:cmd.php

示例11: onReceive

function onReceive($pipe)
{
    global $workers;
    $worker = $workers[$pipe];
    $data = $worker->read();
    if ($data == false) {
        //表示子進程已關閉,回收它
        $status = swoole_process::wait();
        echo "Worker#{$status['pid']} exit\n";
    } else {
        echo "RECV: " . $data;
    }
}
開發者ID:sophia2152,項目名稱:swoole-src,代碼行數:13,代碼來源:async_master.php

示例12: start

 /**
  * @brief 啟動子進程
  */
 public function start()
 {
     $workerNum = $this->_objAha->getConfig()->get('aha', 'worker_num');
     for ($i = 0; $i < $workerNum; $i++) {
         $worker = new \Daemon\Asyncworker($this->_objAha);
         $process = new \swoole_process(array($worker, 'start'));
         //$process->daemon();
         $workerPid = $process->start();
         $this->_workers[$workerPid] = $process;
         $process->write("worker started!");
     }
     foreach ($this->_workers as $process) {
         $workerPid = \swoole_process::wait();
         echo "[Worker Shutdown][WorkerId] {$workerPid} " . PHP_EOL;
         unset($this->_workers[$workerPid]);
     }
 }
開發者ID:vucms,項目名稱:aha,代碼行數:20,代碼來源:Async.php

示例13: _waitChildProcess

 protected function _waitChildProcess()
 {
     //必須為false,非阻塞模式
     //信號發生時可能同時有多個子進程退出
     //必須循環執行wait直到返回false
     $objManager = \Daemon\Library\Ipc\Manager::getInstance();
     while ($result = \swoole_process::wait(false)) {
         $pid = $result['pid'];
         if ($objManager->hasDriveWorker($pid)) {
             $objManager->delDriveWorker($pid);
             \Daemon\Library\Ipc\Shared::delCurrentTaskTable($pid);
             if (!$this->_sigterm) {
                 $objManager->createDriveWorker(\Daemon\Process\Master::getInstance()->getAha(), 1);
             }
         } elseif ($objManager->hasTaskWorker($pid)) {
             $objManager->delTaskWorker($pid);
             \Daemon\Library\Ipc\Shared::delCurrentTaskTable($pid);
             if (!$this->_sigterm) {
                 $objManager->createDirtributeWorker(\Daemon\Process\Master::getInstance()->getAha(), 1);
             }
         } elseif ($objManager->hasRedoWorker($pid)) {
             $objManager->delRedoWorker($pid);
             \Daemon\Library\Ipc\Shared::delCurrentTaskTable($pid);
             if (!$this->_sigterm) {
                 $objManager->createRedoWorker(\Daemon\Process\Master::getInstance()->getAha(), 1);
             }
         } elseif ($objManager->hasStatsWorker($pid)) {
             $objManager->delStatsWorker($pid);
             \Daemon\Library\Ipc\Shared::delCurrentTaskTable($pid);
             if (!$this->_sigterm) {
                 $objManager->createStatsWorker(\Daemon\Process\Master::getInstance()->getAha(), 1);
             }
         } else {
         }
     }
     //如果是SIGTERM信號 並且子進程都已經退出了 父進程終止
     $workers = \Daemon\Library\Ipc\Shared::getCurrentTaskTable();
     if ($this->_sigterm && !$workers->count()) {
         \swoole_event_exit();
     }
 }
開發者ID:eyehere,項目名稱:aha,代碼行數:41,代碼來源:Signal.php

示例14: var_dump

            static $index = 0;
            $index = $index + 1;
            $this->process->push($index . "Hello");
            var_dump($index);
            if ($index == 10) {
                $this->process->push("exit");
                $this->process->push("exit");
                $this->process->push("exit");
                swoole_timer_clear($timer_id);
            }
        });
    }
    public function task_run($worker)
    {
        while (true) {
            $data = $worker->pop();
            var_dump($data);
            if ($data == 'exit') {
                $worker->exit();
            }
            sleep(5);
        }
    }
}
new BaseProcess();
swoole_process::signal(SIGCHLD, function ($sig) {
    //必須為false,非阻塞模式
    while ($ret = swoole_process::wait(false)) {
        echo "PID={$ret['pid']}\n";
    }
});
開發者ID:jinchunguang,項目名稱:swoole-doc,代碼行數:31,代碼來源:muti_process.php

示例15: StartServ

function StartServ($phpStart, $cmd, $name)
{
    $process = new swoole_process(function (swoole_process $worker) use($name, $cmd, $phpStart) {
        //目前指支持一個
        $worker->exec($phpStart, array(STARTBASEPATH . "/lib/Swoole/shell/start.php", $cmd, $name));
        //拉起server
        StartLogTimer(__LINE__ . '   ' . $phpStart . ' ' . STARTBASEPATH . '/lib/Swoole/shell/start.php ' . $cmd . ' ' . $name);
    }, false);
    $pid = $process->start();
    $exeRet = swoole_process::wait();
    if ($exeRet['code']) {
        //創建失敗
        StartLog(" startall  [31;40m [FAIL] [0m" . PHP_EOL);
        return false;
    } else {
        StartLog(" startall  [31;40m [SUCCESS] [0m" . PHP_EOL);
        return true;
    }
}
開發者ID:delphinBlue,項目名稱:tsf,代碼行數:19,代碼來源:swoole.php


注:本文中的swoole_process::wait方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。