Commit 1c710233 authored by chenchuanwen's avatar chenchuanwen

bridgeedit

parent 71752e69
<?php <?php
// 通过链接参数热重载 worker 进程观察触发事件 // 通过链接参数热重载 worker 进程观察触发事件
//if(!empty($request->get)){ if(!empty($request->get)){
// $act = $request->get['act']?$request->get['act']:''; $act = $request->get['act']?$request->get['act']:'';
// if ($act == 'reload') { if ($act == 'reload') {
// echo ' ... Swoole Reloading ! ... ' . PHP_EOL . PHP_EOL; echo ' ... Swoole Reloading ! ... ' . PHP_EOL . PHP_EOL;
// // 触发 reload 之后, 貌似后面的代码也还是会执行的 // 触发 reload 之后, 貌似后面的代码也还是会执行的
// $server->reload(); $server->reload();
// echo ' ... Under Reload ! ... ' . PHP_EOL . PHP_EOL; // 看看 reload 时是否会执行后续的代码 echo ' ... Under Reload ! ... ' . PHP_EOL . PHP_EOL; // 看看 reload 时是否会执行后续的代码
// } elseif ($act == 'stop') { } elseif ($act == 'stop') {
// // 直接立即终止当前 worker 进程, 和 reload 的效果比较相似, 新的 worker 进程的 ID 和原来的一样 // 直接立即终止当前 worker 进程, 和 reload 的效果比较相似, 新的 worker 进程的 ID 和原来的一样
// // 所以程序内部应该尽量避免使用 exit 而应该抛出异常在外部 catch // 所以程序内部应该尽量避免使用 exit 而应该抛出异常在外部 catch
// echo ' ... Swoole Exit ! ... ' . PHP_EOL . PHP_EOL; echo ' ... Swoole Exit ! ... ' . PHP_EOL . PHP_EOL;
// exit; exit;
// } elseif ($act == 'shutdown') { } elseif ($act == 'shutdown') {
// // 直接立即终止当前 worker 进程, 和 reload 的效果比较相似, 新的 worker 进程的 ID 和原来的一样 // 直接立即终止当前 worker 进程, 和 reload 的效果比较相似, 新的 worker 进程的 ID 和原来的一样
// // 所以程序内部应该尽量避免使用 exit 而应该抛出异常在外部 catch // 所以程序内部应该尽量避免使用 exit 而应该抛出异常在外部 catch
// echo ' ... Swoole Shutdown ! ... ' . PHP_EOL . PHP_EOL; echo ' ... Swoole Shutdown ! ... ' . PHP_EOL . PHP_EOL;
// $server->shutdown(); $server->shutdown();
// echo ' ... After Swoole Shutdown ! ... ' . PHP_EOL . PHP_EOL; echo ' ... After Swoole Shutdown ! ... ' . PHP_EOL . PHP_EOL;
// } }
//} }
//if(!empty($request->post)){ if(!empty($request->post)){
try{ try{
$respData=$request->post; $respData=$request->post;
// echo json_encode($respData); // echo json_encode($respData);
...@@ -50,4 +50,4 @@ ...@@ -50,4 +50,4 @@
}catch(Exception $ex){ }catch(Exception $ex){
throw new Exception($ex->getMessage(),$ex->getCode()); throw new Exception($ex->getMessage(),$ex->getCode());
} }
//} }
...@@ -20,37 +20,6 @@ $http->set(array( ...@@ -20,37 +20,6 @@ $http->set(array(
'daemonize' => false, 'daemonize' => false,
)); ));
// 服务器启动时执行一次
$http->on('Start', function (Swoole_Http_Server $server) {
echo PHP_EOL . PHP_EOL . 'Start: http://b.shenbd.com' . PHP_EOL . PHP_EOL;
});
// 服务器启动时执行一次
$http->on('ManagerStart', function (Swoole_Http_Server $server) {
echo 'ManagerStart: ' . PHP_EOL . PHP_EOL;
});
// 每个 Worker 进程启动或重启时都会执行
$http->on('WorkerStart', function (Swoole_Http_Server $server,$workerId) {
// 通过重新加载外部文件来重载代码和释放之前占用的内存
//include_once __DIR__ . DIRECTORY_SEPARATOR .'workerstart.php';
// 下面这些直接写在当前文件中的代码即便重载也不会变化
echo 'WorkerStart: ' . PHP_EOL . PHP_EOL;
echo ' Worker ID: ' . $workerId . PHP_EOL . PHP_EOL;
// 启动服务器后, 去掉下面这行注释, 然后 reload , 该语句也不会执行的
//echo ' reloaded ! ' . PHP_EOL . PHP_EOL;
// 应该把这里的回调事件代码写在另一个文件中来 include 而不是直接写在这里
// 注意即便是 include_once , reload 也会重新加载的, 但在你的逻辑控制中是有效的
});
// 每次连接时(相当于每个浏览器第一次打开页面时)执行一次, reload 时连接不会断开, 也就不会再次触发该事件
$http->on('Connect', function (Swoole_Http_Server $server, $fd,$reactorThreadId) {
echo 'Connect: ' . PHP_EOL . PHP_EOL;
echo ' Worker ID: '. $server->worker_id . PHP_EOL . PHP_EOL;
echo ' fd: ' . $fd . ' , fromId: ' . $reactorThreadId . PHP_EOL . PHP_EOL;
});
$http->on('request', function ($request, $response) { $http->on('request', function ($request, $response) {
require_once APPLICATION_PATH . '/scripts/crontab/common.php'; require_once APPLICATION_PATH . '/scripts/crontab/common.php';
require_once APPLICATION_PATH . '/scripts/crontab/push/bridgeBase.php'; require_once APPLICATION_PATH . '/scripts/crontab/push/bridgeBase.php';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment