本文整理匯總了PHP中swoole_process::exit方法的典型用法代碼示例。如果您正苦於以下問題:PHP swoole_process::exit方法的具體用法?PHP swoole_process::exit怎麽用?PHP swoole_process::exit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類swoole_process
的用法示例。
在下文中一共展示了swoole_process::exit方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: callback_function
function callback_function(swoole_process $worker)
{
//echo "Worker: start. PID=".$worker->pid."\n";
//recv data from master
$recv = $worker->pop();
echo "From Master: {$recv}\n";
sleep(2);
$worker->exit(0);
}
示例2: child_sync
function child_sync(swoole_process $worker)
{
//echo "Worker: start. PID=".$worker->pid."\n";
//recv data from master
$recv = $worker->read();
echo "From Master: {$recv}\n";
//send data to master
$worker->write("hello master\n");
sleep(2);
$worker->exit(0);
}
示例3: callback_process_function
function callback_process_function(swoole_process $worker)
{
set_time_limit(300);
$task = json_decode($worker->read(), true);
$worker->name('crontab.php worker=' . $task['uniqid']);
$Handle = new TimingCall_Handle($task);
$Handle->upNextExecuteTime();
$Handle->refreshStatistics();
$Handle->Execute();
$worker->exit(0);
}
示例4: callback_function
function callback_function(swoole_process $worker)
{
//echo "Worker: start. PID=".$worker->pid."\n";
//recv data from master
$cnt = 0;
while ($cnt < 2) {
// 如果隊列裏沒有數據,則pop方法阻塞等待
$recv = $worker->pop();
echo "From Master: {$recv}\n";
$cnt++;
}
sleep(1);
$worker->exit(0);
}
示例5: onTmpProcess
public function onTmpProcess(swoole_process $worker)
{
$cmd = $worker->read();
$handle = popen($cmd, 'r');
swoole_event_add($worker->pipe, function () use($worker, $handle) {
$cmd = $worker->read();
if ($cmd == 'exit') {
$worker->exit();
}
fwrite($handle, $cmd);
});
while (!feof($handle)) {
$buffer = fread($handle, 18192);
echo $buffer;
}
}
示例6: while
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;
}
}
//循環創建進程
for ($i = 0; $i < $worker_num; $i++) {
$process = new swoole_process(function (swoole_process $process) {
$i = 1;
while ($i++) {
$process->write("Worker#{$process->id}: hello master\n");
if ($i > 5 and $process->id == 1) {
$process->exit();
}
sleep(1);
}
});
$process->id = $i;
$pid = $process->start();
$workers[$process->pipe] = $process;
}
//將子進程的管道加入EventLoop
foreach ($workers as $process) {
swoole_event_add($process->pipe, 'onReceive');
}