当前位置: 首页>>代码示例>>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;未经允许,请勿转载。