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


PHP swoole_process::signal方法代碼示例

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


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

示例1: register_signal

 public static function register_signal()
 {
     swoole_process::signal(SIGUSR2, function ($signal_num) {
         echo "收到結束信號,結束進程\n";
         exit;
     });
 }
開發者ID:stonegithubs,項目名稱:squire,代碼行數:7,代碼來源:Squire_Gearman.class.php

示例2: 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

示例3: 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])) {
                 $task = self::$worker_list[$pid];
                 $id = $task['id'];
                 $task['process']->close();
                 unset(self::$worker_list[$pid]);
                 if (isset(self::$unique_task_list[$id]) && self::$unique_task_list[$id] > 0) {
                     self::$unique_task_list[$id]--;
                 }
                 defined('PHPKIT_RUN_DEBUG') && syslog(LOG_INFO, 'child process exit:' . $pid);
             }
         }
     });
     //終止進程,用戶定義信號1
     \swoole_process::signal(SIGUSR1, function ($signo) {
         //TODO something
     });
     defined('PHPKIT_RUN_DEBUG') && syslog(LOG_INFO, 'register signal success');
 }
開發者ID:mawenpei,項目名稱:swoole-crontab,代碼行數:32,代碼來源:Handler.php

示例4: 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

示例5: 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

示例6: child_async

function child_async(swoole_process $worker)
{
    //echo "Worker: start. PID=".$worker->pid."\n";
    //recv data from master
    $GLOBALS['worker'] = $worker;
    global $argv;
    $worker->name("{$argv[0]}: worker");
    swoole_process::signal(SIGTERM, function ($signal_num) use($worker) {
        echo "signal call = {$signal_num}, #{$worker->pid}\n";
    });
    swoole_event_add($worker->pipe, function ($pipe) use($worker) {
        $recv = $worker->read();
        echo "From Master: {$recv}\n";
        $worker->write("hello master\n");
    });
}
開發者ID:stonegithubs,項目名稱:swoole-game,代碼行數:16,代碼來源:server.php

示例7: 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

示例8: callback_function

                swoole_process::kill($process->pid);
            }
        }
    });
}
//開啟子進程進行異步處理
function callback_function(swoole_process $worker)
{
    $GLOBALS['worker'] = $worker;
    swoole_event_add($worker->pipe, function ($pipe) {
        $worker = $GLOBALS['worker'];
        $recv = $worker->read();
        if ($recv) {
            $data = call_user_func_array('dosomething', [json_decode($recv, true)]);
            $worker->write($data);
        } else {
            $worker->write('');
        }
    });
}
swoole_process::signal(SIGCHLD, function ($signo) use($worker_num) {
    static $worker_count = 0;
    while ($ret = swoole_process::wait(false)) {
        echo 'Worker Exit, pid=', $ret['pid'], PHP_EOL;
        $worker_count++;
        if ($worker_count >= $worker_num) {
            echo memory_get_usage(true) / 1024 / 1024, PHP_EOL;
            swoole_event_exit();
        }
    }
});
開發者ID:xingcuntian,項目名稱:ssos,代碼行數:31,代碼來源:test_process.php

示例9: my_onWorkerStart

function my_onWorkerStart(swoole_server $serv, $worker_id)
{
    processRename($serv, $worker_id);
    if (!$serv->taskworker) {
        swoole_process::signal(SIGUSR2, function ($signo) {
            echo "SIGNAL: {$signo}\n";
        });
        //        swoole_timer_tick(2000, function($id) {
        //            var_dump($id);
        //        });
    } else {
        $serv->tick(1000, function ($id) use($serv) {
            if (G::$index > 10) {
                $serv->after(2500, 'timer_show', 2);
                G::$index = 0;
            } else {
                G::$index++;
            }
            timer_show($id);
        });
    }
    //forkChildInWorker();
    //	setTimerInWorker($serv, $worker_id);
}
開發者ID:lanteng77,項目名稱:swoole-src,代碼行數:24,代碼來源:server.php

示例10: array

{
    $binpath = $_SERVER["_"];
    $worker->exec($binpath, array(ROOT_PATH . "http_test.php", $worker->pipe));
}
$process = new swoole_process("fork");
$process->start();
function process_run($worker)
{
    echo "abc\n";
    $worker->exit(0);
    exit;
}
function create_process()
{
    $process = new swoole_process("process_run");
    $process->start();
}
swoole_timer_add(1000, function ($interval) {
    create_process();
    create_process();
});
swoole_process::signal(SIGCHLD, function ($signo) {
    while ($pid = pcntl_wait($status, WNOHANG)) {
        echo $pid . "\n";
    }
});
swoole_event_add($process->pipe, function ($pipe) use($process) {
    $ret = $process->read();
    echo $ret;
    $process->write($ret);
});
開發者ID:jymsy,項目名稱:swoole-crontab,代碼行數:31,代碼來源:process_test.php

示例11: my_onWorkerStart

function my_onWorkerStart(swoole_server $serv, $worker_id)
{
    processRename($serv, $worker_id);
    if (!$serv->taskworker) {
        swoole_process::signal(SIGUSR2, function ($signo) {
            echo "SIGNAL: {$signo}\n";
        });
        $serv->defer(function () {
            echo "defer call\n";
        });
    } else {
        //        swoole_timer_after(2000, function() {
        //            echo "after 2 secends.\n";
        //        });
        //        $serv->tick(1000, function ($id) use ($serv) {
        //            if (G::$index > 10) {
        //                $serv->after(2500, 'timer_show', 2);
        //                G::$index = 0;
        //            } else {
        //                G::$index++;
        //            }
        //            timer_show($id);
        //        });
    }
    //forkChildInWorker();
    //	setTimerInWorker($serv, $worker_id);
}
開發者ID:noikiy,項目名稱:swoole-src,代碼行數:27,代碼來源:server.php

示例12: register_signal

 /**
  * 注冊信號
  */
 private static function register_signal()
 {
     swoole_process::signal(SIGTERM, function ($signo) {
         self::exit2p("收到退出信號,退出主進程");
     });
     swoole_process::signal(SIGCHLD, function ($signo) {
         while ($ret = swoole_process::wait(false)) {
             $pid = $ret['pid'];
             if (isset(self::$task_list[$pid])) {
                 $task = self::$task_list[$pid];
                 if ($task["type"] == "crontab") {
                     $end = microtime(true);
                     $start = $task["start"];
                     $id = $task["id"];
                     Main::log_write("{$id} [Runtime:" . sprintf("%0.6f", $end - $start) . "]");
                     $task["process"]->close();
                     //關閉進程
                     unset(self::$task_list[$pid]);
                     if (isset(self::$unique_list[$id]) && self::$unique_list[$id] > 0) {
                         self::$unique_list[$id]--;
                     }
                 }
                 if ($task["type"] == "worker") {
                     $end = microtime(true);
                     $start = $task["start"];
                     $classname = $task["classname"];
                     Main::log_write("{$classname}_{$task["number"]} [Runtime:" . sprintf("%0.6f", $end - $start) . "]");
                     $task["process"]->close();
                     //關閉進程
                     (new Worker())->create_process($classname, $task["number"], $task["redis"]);
                 }
             }
         }
     });
     swoole_process::signal(SIGUSR1, function ($signo) {
         //TODO something
     });
 }
開發者ID:meimingmm,項目名稱:swoole-crontab,代碼行數:41,代碼來源:Crontab.class.php

示例13: child_async

 function child_async(swoole_process $worker)
 {
     //echo "Worker: start. PID=".$worker->pid."\n";
     global $argv;
     $worker->name("{$argv[0]}: worker #" . $worker->id . "/" . $this->worker_num);
     swoole_process::signal(SIGTERM, function ($signal_num) use($worker) {
         echo "signal call = {$signal_num}, #{$worker->pid}\n";
     });
     switch ($this->status) {
         case 'import':
             echo " worker #" . $worker->id . "/" . $this->worker_num . " enter status: " . $this->status . PHP_EOL;
             $this->import_data($worker);
             break;
         case '1-dim':
             echo " worker #" . $worker->id . "/" . $this->worker_num . " enter status: " . $this->status . PHP_EOL;
             $this->generate_1dim_rank($worker);
             break;
         case '2-dim':
             echo " worker #" . $worker->id . "/" . $this->worker_num . " enter status: " . $this->status . PHP_EOL;
             $this->generate_2dim_rank($worker);
             break;
         case '3-dim':
             echo " worker #" . $worker->id . "/" . $this->worker_num . " enter status: " . $this->status . PHP_EOL;
             $this->generate_3dim_rank($worker);
             break;
         default:
             break;
     }
     $worker->exit(0);
 }
開發者ID:shenxinyu,項目名稱:redis_rank,代碼行數:30,代碼來源:paralle_rank.php

示例14: my_onWorkerStart

function my_onWorkerStart($serv, $worker_id)
{
    processRename($serv, $worker_id);
    if (!$serv->taskworker) {
        swoole_process::signal(SIGUSR2, function ($signo) {
            echo "SIGNAL: {$signo}\n";
        });
    }
    //forkChildInWorker();
    //	setTimerInWorker($serv, $worker_id);
}
開發者ID:WenkeZhou,項目名稱:swoole-src,代碼行數:11,代碼來源:server.php

示例15: process_signal

/**
 * @param $signo
 * @param callable $callback
 * @return mixed
 */
function process_signal($signo, callable $callback)
{
    return swoole_process::signal($signo, $callback);
}
開發者ID:JanHuang,項目名稱:swoole,代碼行數:9,代碼來源:helpers.php


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