php中Swoole的热更新实现代码实例 |
使用 如何安装 #!/bin/sh # src 需要监控的地址 src=/home/server/Project/test/app/ /usr/bin/inotifywait -rmq -e create,modify,delete $src | while read event do /home/server/Project/test/bin/httpserver reload done linux shell 写swoole重启脚本代码如下 #!/bin/sh kill `lsof -t -i:9501` sleep 2 php /data/web/mircoweb/wwwroot/Public/swoole.php sleep 1 netstat -ntlp 如果不支持lsof命令 那就yum install lsof安装下吧 swoole服务平滑重启 1. reload.sh脚本 echo "loading..." pid="pidof live_name" echo $pid kill -USR1 $pid echo "loading success" 2. linux中执行
swoole_reload_server.php <?php class Server { private $serv; public function __construct() { $this->serv = new swoole_server("0.0.0.0", 9501); $this->serv->set(array( 'worker_num' => 8, 'daemonize' => false, 'max_request' => 10000, 'dispatch_mode' => 2, 'debug_mode'=> 1, )); $this->serv->on('Start', array($this, 'onStart')); $this->serv->on('WorkerStart', array($this, 'onWorkerStart')); $this->serv->on('Connect', array($this, 'onConnect')); $this->serv->on('Receive', array($this, 'onReceive')); $this->serv->on('Close', array($this, 'onClose')); $this->serv->start(); } public function onStart( $serv ) { echo "Start "; cli_set_process_title("reload_master"); } public function onWorkerStart( $serv , $worker_id) { require_once "reload_page.php"; Test(); } public function onConnect( $serv, $fd, $from_id ) { echo "Client {$fd} connect "; } public function onReceive( swoole_server $serv, $fd, $from_id, $data ) { echo "Get Message From Client {$fd}:{$data} "; } public function onClose( $serv, $fd, $from_id ) { echo "Client {$fd} close connection "; } } new Server(); reload.sh echo "Reloading..." cmd=$(pidof reload_master) kill -USR1 "$cmd" echo "Reloaded" reload_page.php <?php /** * If you change this function and want * swoole_server to use the new function, * just run 'reload.sh' to send a restart * signal to swoole_server. */ function Test() { echo "This is not a php file "; } 到此这篇关于php中SWOOLE的热更新实现代码实例的文章就介绍到这了,更多相关php中SWOOLE的热更新实现内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家! |