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


PHP swoole_process::kill方法代碼示例

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


在下文中一共展示了swoole_process::kill方法的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: reload

 public static function reload()
 {
     $pid = file_get_contents(Main::$pidFile);
     if ($pid) {
         $res = swoole_process::kill($pid, SIGUSR1);
         if ($res) {
             Main::log("reload success");
         }
     } else {
         Main::log("進程不存在,reload失敗");
     }
 }
開發者ID:xuguoliangjj,項目名稱:swoole_crontab,代碼行數:12,代碼來源:Crontab.php

示例3: stop

 /**
  * 停止服務
  */
 public static function stop()
 {
     $pid = file_get_contents(self::$pid_file);
     if ($pid) {
         if (\swoole_process::kill($pid, 0)) {
             \swoole_process::kill($pid, SIGTERM);
         } else {
             @unlink(self::$pid_file);
         }
         defined('PHPKIT_RUN_DEBUG') && syslog(LOG_INFO, self::$process_name . ' exit success');
     }
 }
開發者ID:mawenpei,項目名稱:swoole-crontab,代碼行數:15,代碼來源:HandlerTrait.php

示例4: swoole_process

//啟動4個進程進行處理
$worker_num = 4;
for ($i = 0; $i < $worker_num; $i++) {
    $process = new swoole_process('callback_function', false, true);
    $pid = $process->start();
    $process->write(dotest());
    $process->pid = $pid;
    // $workers[$pid] = $process;
    swoole_event_add($process->pipe, function ($pipe) use($process) {
        $recv = $process->read();
        if ($recv != '') {
            $data = dotest();
            if ($data != false) {
                $process->write($data);
            } else {
                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 {
開發者ID:xingcuntian,項目名稱:ssos,代碼行數:31,代碼來源:test_process.php

示例5: stop

 /**
  * 停止進程
  * @param bool $output
  */
 public static function stop($output = true)
 {
     $pid = @file_get_contents(self::$pid_file);
     if ($pid) {
         if (swoole_process::kill($pid, 0)) {
             swoole_process::kill($pid, SIGTERM);
             Main::log_write("進程" . $pid . "已結束");
         } else {
             @unlink(self::$pid_file);
             Main::log_write("進程" . $pid . "不存在,刪除pid文件");
         }
     } else {
         $output && Main::log_write("需要停止的進程未啟動");
     }
 }
開發者ID:meimingmm,項目名稱:swoole-crontab,代碼行數:19,代碼來源:Crontab.class.php

示例6: checkStatus

 public function checkStatus()
 {
     $args = getopt('s:');
     if (isset($args['s'])) {
         switch ($args['s']) {
             case 'reload':
                 $pid = file_get_contents($this->cacheDir . "/pid");
                 echo "當前進程" . $pid . "\n";
                 echo "熱重啟中\n";
                 if ($pid) {
                     if (swoole_process::kill($pid, 0)) {
                         swoole_process::kill($pid, SIGUSR1);
                     }
                 }
                 echo "重啟完成\n";
                 swoole_process::daemon();
                 break;
             default:
                 break;
         }
         exit;
     }
 }
開發者ID:fucongcong,項目名稱:framework,代碼行數:23,代碼來源:RpcKernal.php

示例7: params_m

 /**
  * 監控進程是否在運行
  * @param $opt
  * @return array
  */
 public static function params_m($opt)
 {
     if (isset($opt["m"]) || isset($opt["monitor"])) {
         $pid = @file_get_contents(Crontab::$pid_file);
         if ($pid && swoole_process::kill($pid, 0)) {
             exit;
         } else {
             $opt = array("s" => "restart");
         }
     }
     return $opt;
 }
開發者ID:noikiy,項目名稱:swoole-crontab,代碼行數:17,代碼來源:main.php

示例8: onWorkerStop

 public function onWorkerStop(\swoole_http_server $server, $worker_id)
 {
     if ($worker_id) {
         return true;
     }
     $worker_pids = $this->shm->get('worker_pid');
     foreach ($worker_pids as $worker_pid) {
         \swoole_process::kill($worker_pid, 9);
     }
     $this->shm->del("worker_pid");
     return true;
 }
開發者ID:millken,項目名稱:ypf,代碼行數:12,代碼來源:Swoole.php

示例9: register_signal

 /**
  * 注冊信號
  */
 private static function register_signal()
 {
     swoole_process::signal(SIGTERM, function ($signo) {
         if (!empty(Main::$http_server)) {
             swoole_process::kill(Main::$http_server->pid, SIGKILL);
         }
         self::exit2p("收到退出信號,退出主進程");
     });
     swoole_process::signal(SIGCHLD, function ($signo) {
         while (($pid = pcntl_wait($status, WNOHANG)) > 0) {
             $task = self::$task_list[$pid];
             $end = microtime(true);
             $start = $task["start"];
             $id = $task["id"];
             Main::log_write("{$id} [Runtime:" . sprintf("%0.6f", $end - $start) . "]");
             unset(self::$task_list[$pid]);
             if (isset(self::$unique_list[$id]) && self::$unique_list[$id] > 0) {
                 self::$unique_list[$id]--;
             }
         }
     });
     swoole_process::signal(SIGUSR1, function ($signo) {
         LoadConfig::reload_config();
     });
 }
開發者ID:royalwang,項目名稱:swoole-crontab,代碼行數:28,代碼來源:Crontab.class.php

示例10: exitprocess

 /**
  * 結束已開進程
  * @param $workers
  */
 public static function exitprocess($workers)
 {
     foreach ($workers as $task => $data) {
         foreach (self::$workers as $pid => $process) {
             if ($process["task"] == $task) {
                 Squire_Master::$workers[$pid]["logout"] = true;
                 swoole_process::kill($pid, SIGUSR2);
                 unset(self::$process_list[$task]);
             }
         }
     }
 }
開發者ID:stonegithubs,項目名稱:squire,代碼行數:16,代碼來源:Squire_Master.class.php

示例11: _killAllProcess

 protected function _killAllProcess()
 {
     $this->_sigterm = true;
     $workers = \Daemon\Library\Ipc\Manager::getInstance()->getWorkersPid();
     foreach ($workers as $pid) {
         \swoole_process::kill($pid, SIGUSR1);
     }
 }
開發者ID:eyehere,項目名稱:aha,代碼行數:8,代碼來源:Signal.php

示例12: swoole_process

Console::put("swoole_get_local_ip()", !is_array(swoole_get_local_ip()));
Console::put("swoole_version()", !is_string(swoole_version()));
if (!class_exists('swoole_process')) {
    Console::put("no have swoole_process", true, true);
}
$server = new swoole_process(function ($process) {
    $php = $_SERVER['_'];
    return $process->exec($php, array(__DIR__ . "/../examples/server.php", 'daemon'));
}, false, false);
if (!$server->start()) {
    Console::put("Server start failed.", true, true);
}
usleep(200000);
register_shutdown_function(function () {
    global $server;
    if (swoole_process::kill($server->pid, SIGTERM)) {
        Console::put("swoole_process::kill()");
        $status = swoole_process::wait();
        Console::put("swoole_process::wait()", !($status['pid'] == $server->pid));
    } else {
        Console::put("swoole_process::kill()", true);
    }
    echo "------------------------------------------------------------------\n";
    echo "Swoole UnitTest Finish.\n";
});
/**
 * UnitTests for swoole server.
 * This is just a client. Server see examples/server.php
 */
$client = new swoole_client(SWOOLE_TCP);
if (!$client->connect('127.0.0.1', 9501)) {
開發者ID:zzjin,項目名稱:swoole-src,代碼行數:31,代碼來源:unittest.php

示例13: test_taskWaitMulti

    Console::put("swoole_server->taskwait()", $data and $data == 'taskwaitok');
    Console::put("swoole_server->taskWaitMulti()", test_taskWaitMulti($client));
}
$client->send("close");
$data = $client->recv();
Console::put("swoole_server->close()", $data == '');
echo "------------------------------------------------------------------\n";
Console::put("swoole_client[TCP]->recv()", true);
Console::put("swoole_client[TCP]->recv(256K, MSG_WAITALL)", $sendBigPkgTest);
$sockname = $client->getsockname();
Console::put("swoole_client[TCP]->getsockname()", is_array($sockname));
echo "------------------------------------------------------------------\n";
Console::put("swoole_client[TCP]->close()", $client->close());
echo "------------------------------------------------------------------\n";
$client = new swoole_client(SWOOLE_UDP);
Console::put("swoole_client[UDP]->connect()", $client->connect('127.0.0.1', 9502));
Console::put("swoole_client[UDP]->send()", $client->send("hello"));
$data = $client->recv();
Console::put("swoole_client[UDP]->recv()", $data and $data == 'Swoole: hello');
$peername = $client->getpeername();
Console::put("swoole_client[UDP]->getpeername()", is_array($peername) and $peername['port'] == 9502);
echo "------------------------------------------------------------------\n";
/**
 * Server測試結束,關閉服務器
 */
swoole_process::kill($server->pid + 1, SIGTERM);
Console::put("swoole_process::kill()");
$status = swoole_process::wait();
Console::put("swoole_process::wait()", $status['pid'] == $server->pid);
echo "------------------------------------------------------------------\n";
echo "Swoole UnitTest Finish.\n";
開發者ID:swoole,項目名稱:tests,代碼行數:31,代碼來源:run-tests.php

示例14: stop

 public static function stop()
 {
     $pid = @file_get_contents(self::$pid_file);
     if ($pid) {
         if (swoole_process::kill($pid, 0)) {
             swoole_process::kill($pid, SIGTERM);
             Main::log_write("進程" . $pid . "已結束");
         }
     } else {
         Main::log_write("未找到啟動的進程號");
     }
     @unlink(self::$pid_file);
 }
開發者ID:xufei100,項目名稱:swoole-crontab,代碼行數:13,代碼來源:main_1.php

示例15: process_kill

/**
 * Kill somebody
 *
 * @param $pid
 * @param int $signo
 * @return int
 */
function process_kill($pid, $signo = SIGTERM)
{
    return swoole_process::kill($pid, $signo);
}
開發者ID:JanHuang,項目名稱:swoole,代碼行數:11,代碼來源:helpers.php


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