include_once 'index.php';
$ip = '0.0.0.0';
$port = 9501;
$mysql_chain = 0.5;//数据库重连时间(分钟)
$http = new swoole_http_server($ip, $port);
\app\confg\web::run();
$http->set(
array(
'worker_num' => 10, //开启worker进程数量
'max_request' => 200000,//最大任务重启
'log_level' => 5,//开启报错级别,可以带来性能的提升
'dispatch_mode' => 3,
'task_worker_num' => 5,//task进程,同时是mysql链接进程数量
// 'daemonize' => 1,//开启守护进程
'log_file' => '/home/log/swoole' . date('Ymd', time()) . '.log'//记录所有日志信息
));
$http->addListener($ip, $port, SWOOLE_SOCK_UDP);
$http->on('Packet', '\style\lib\UpdController::run');//处理UPD数据操作
$http->on("start", function ($http) {
//数据库初始化
time_log('系统开始运行可以通过地址访问 http://IP');
});
$http->on("request", function ($resp, $response) use ($http) {
try {
\style\longrbl::run($resp, $response, $http);
} catch (\Exception $e) {
$response->header("Content-Type", "text/html; charset=utf-8");
$response->end("
" . $e->getMessage() . "");
}
});
$http->on('WorkerStart', function ($service, $worker_id) use ($mysql_chain) {
if ($service->taskworker) {
try {
\style\lib\db\Db::run();
$service->tick($mysql_chain * 60 * 1000, function () {//心跳检测当前mysql连接
\style\lib\db\Db::ping_mysql();//心跳检测
});
} catch (Exception $e) {
echo time_log($e->getMessage());
}
}
});
$http->on('Task', function ($http, $task_id, $src_worker_id, $data) {
$task_service['task_id'] = $task_id;//当前task进程的id
$task_service['ser_worker_id'] = $src_worker_id;// 当前任务来着那个worker进程
try {
\style\longrbl::task_tun($data, $http, $task_service);
} catch (Exception $e) {
echo time_log($e->getMessage());
}
});
$http->on('Finish', function ($serv, $task_id, $data) {
});
/**
* 输出当前日志
* @param $data
*/
function time_log($data)
{
echo '[' . date('Y-m-d h:i:s', time()) . ']->' . $data . PHP_EOL;
}
$http->start();
一键复制
编辑
Web IDE
原始数据
按行查看
历史