本文整理汇总了PHP中swoole_server::shutdown方法的典型用法代码示例。如果您正苦于以下问题:PHP swoole_server::shutdown方法的具体用法?PHP swoole_server::shutdown怎么用?PHP swoole_server::shutdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swoole_server
的用法示例。
在下文中一共展示了swoole_server::shutdown方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onReceive
public function onReceive(swoole_server $server, $fd, $from_id, $data)
{
if (empty($data)) {
// 发送数据给客户端,请求包错误
$data = array('code' => 500, 'msg' => '非法请求', 'data' => null);
$server->send($fd, json_encode($data));
}
//局域网管理
$udpClient = $server->connection_info($fd, $from_id);
if ($udpClient['server_port'] == '9502') {
$data = str_replace("\r\n\r\n", "", $data);
switch ($data) {
case 'stop':
echo '服务器关闭: ' . date('Y-m-d H:i:s') . PHP_EOL;
$server->shutdown();
$server->send($fd, '服务器关闭成功');
break;
case 'reload':
echo 'Worker进程重启: ' . date('Y-m-d H:i:s') . PHP_EOL;
$server->reload();
$server->send($fd, '服务器Worker重启成功');
break;
default:
$server->send($fd, '非法请求');
break;
}
} else {
$data = json_decode($data, true);
echo $data['name'] . " say hello " . Test::WORD . "\n";
$server->send($fd, $data['name'] . " say hello " . Test::WORD);
}
}
示例2: on_receive
/**
* listen on receive data
*
* @param \swoole_server $serv
* @param $fd
* @param $from_id
* @param $data
*/
public function on_receive(\swoole_server $serv, $fd, $from_id, $data)
{
// format passed
$data = str_replace(self::EOFF, '', $data);
$data = unserialize($data);
// check is signal for server shutdown
if (!empty($data['shutdown']) || !empty($data['reload'])) {
// try to clear timers
$this->__clear_timer();
$send = !empty($data['shutdown']) ? $serv->shutdown() : $serv->reload();
$send = serialize($send);
$send .= self::EOFF;
$ends = $serv->send($fd, $send);
if ($ends) {
$serv->close($fd);
}
return;
}
// dont send back
if (!empty($data['return']) && $data['return'] === FALSE) {
$back = serialize(TRUE);
$back .= self::EOFF;
$serv->send($fd, $back);
$serv->close($fd);
}
// now post data to a task
$param = ['fd' => $fd, 'data' => $data];
$param = serialize($param);
$param .= self::EOFF;
// worker direct
$this->on_task($serv, NULL, NULL, $param);
return;
}
示例3: onReceive
public function onReceive(\swoole_server $server, $fd, $from_id, $data)
{
$data = trim($data);
if ($data == 'Stop') {
//停止
$server->shutdown();
$server->send($fd, 'success', $from_id);
} else {
if ($data == 'Stats') {
//状态
$data = $server->stats();
$server->send($fd, json_encode($data), $from_id);
} else {
if ($data == 'Reload') {
//重启
$server->reload();
$server->send($fd, 'success', $from_id);
} else {
if ($data == 'ResetTelnet') {
//重置所有telnet链接
} else {
$data = json_decode($data, true);
if ($data['act'] == 'Telnet' && isset($data['ip']) && isset($data['cmd'])) {
//执行命令
$service = TelnetEvent::getService($data['ip']);
if ($service == null) {
$result['code'] = 2;
} else {
if ($data['cmd'] > 0) {
if (isset($data['arg'])) {
$result['data'] = $service->exec($data['cmd'], $data['arg']);
} else {
$result['data'] = $service->exec($data['cmd']);
}
if ($result == null || $result['data'] == null) {
$result = ['code' => 3];
} else {
$result['code'] = 1;
}
} else {
$service->getSwitch()->connect();
if ($service->getSwitch()->isConnect()) {
$result['code'] = 1;
} else {
$result['code'] = 3;
}
}
}
$server->send($fd, json_encode($result), $from_id);
} else {
$server->send($fd, 'unknown command!', $from_id);
}
}
}
}
}
$server->close($fd);
}
示例4: shutdown
function shutdown()
{
return $this->sw->shutdown();
}
示例5: stop
public function stop()
{
$this->server->shutdown();
}
示例6: array
<?php
/**
* Created by PhpStorm.
* User: zhaoquan
* Date: 15-5-29
* Time: 下午2:59
*/
$server = new swoole_server("127.0.0.1", 9021, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);
$setting = array('daemonize' => 0, 'reactor_num' => 2, 'worker_num' => 4, 'max_request' => 2000, 'backlog' => 128, 'open_cpu_affinity' => 1, 'open_tcp_nodelay' => 1, 'log_file' => '../log/swoole_test.log', 'heartbeat_check_interval' => 30, 'heartbeat_idle_time' => 60, 'dispatch_mode' => 2);
$server->set($setting);
var_dump($server->setting);
$server->on("connect", function ($server, $fd) {
echo "connect\n";
});
$server->on("receive", function ($server, $fd, $from_id, $data) {
$server->send($fd, 'Swoole: ' . $data);
$server->close($fd);
});
$server->on("close", function ($server, $fd) {
echo "close\n";
$server->shutdown();
});
$server->start();
示例7: shutdown
public function shutdown()
{
return $this->server->shutdown();
}
示例8: onReceive
public function onReceive(\swoole_server $server, $fd, $fromId, $data)
{
if ($data == $this->preSysCmd . "reload") {
$ret = intval($server->reload());
$server->send($fd, $ret);
} elseif ($data == $this->preSysCmd . "info") {
$info = $server->connection_info($fd);
$server->send($fd, 'Info: ' . var_export($info, true) . PHP_EOL);
} elseif ($data == $this->preSysCmd . "stats") {
$serv_stats = $server->stats();
$server->send($fd, 'Stats: ' . var_export($serv_stats, true) . PHP_EOL);
} elseif ($data == $this->preSysCmd . "shutdown") {
$server->shutdown();
} else {
$this->protocol->onReceive($server, $fd, $fromId, $data);
}
}
示例9: onReceive
/**
* 对外提供接口
*
* @param $server swoole_server对象
* @param $fd TCP客户端连接的文件描述符
* @param $from_id TCP连接所在的Reactor线程ID
* @param $data 收到的数据内容
*/
public function onReceive(swoole_server $server, $fd, $from_id, $data)
{
if (empty($data)) {
// 发送数据给客户端,请求包错误
$data = array('code' => 500, 'msg' => '非法请求', 'data' => null);
$server->send($fd, json_encode($data));
}
//局域网管理
$udpClient = $server->connection_info($fd, $from_id);
if ($udpClient['server_port'] == '9504') {
echo $data . PHP_EOL;
switch ($data) {
case 'stop':
echo '服务器关闭: ' . date('Y-m-d H:i:s') . PHP_EOL;
$server->shutdown();
$server->send($fd, '服务器关闭成功');
break;
case 'reload':
echo 'Worker进程重启: ' . date('Y-m-d H:i:s') . PHP_EOL;
$server->reload();
$server->send($fd, '服务器Worker重启成功');
break;
default:
$server->send($fd, '非法请求');
break;
}
} else {
$data = json_decode($data, true);
//任务数据
$list = $data['list'];
//请求类型
$type = $data['type'];
switch ($type) {
//添加定时器
case 'add':
//添加定时器
$timeInterval = $list['s_interval'];
$taskId = $list['s_id'];
$timerId = $server->tick($timeInterval, array($this, 'onTimer'), $list);
//更新任务
Task::updateTimer($taskId, $timerId);
$data = array('code' => 200, 'msg' => '添加定时器成功', 'data' => null);
$server->send($fd, json_encode($data));
break;
//修改定时器
//修改定时器
case 'edit':
//修改url,定时器间隔时间
$data = array('code' => 200, 'msg' => '修改定时器成功', 'data' => null);
$server->send($fd, json_encode($data));
break;
//删除定时器
//删除定时器
case 'del':
echo '删除定时器: ' . date('Y-m-d H:i:s') . PHP_EOL;
//任务ID
$taskId = $list['s_id'];
//定时器ID
$timerId = $list['s_timerId'];
//删除定时器
swoole_timer_clear($timerId);
//删除任务
Task::delTask($taskId);
$data = array('code' => 200, 'msg' => '删除定时器成功', 'data' => null);
$server->send($fd, json_encode($data));
break;
default:
$data = array('code' => 500, 'msg' => '非法请求', 'data' => null);
$server->send($fd, json_encode($data));
break;
}
}
}
示例10: onManagerStop
public final function onManagerStop(\swoole_server $serv)
{
echo "Manager Stop , shutdown server\n";
$serv->shutdown();
}
示例11: shutdown
/**
* 结束
* @return [type] [description]
*/
public function shutdown(\swoole_server $serv)
{
$serv->shutdown();
}