本文整理汇总了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');
}