在平时使用swoole进行开发时,经常会遇到这个问题。更改代码后,手动ctrl+c中断服务,再输入命令重启服务。频繁重启让我感到疲倦。PHP提供inotify扩展,调用linux的inotify系统调用,监听文件变化。这时,一个想法冒了出来。我开了一个主进程监控文件变化,然后开了一个子进程运行swoole服务。主进程监听到文件变化后,kill子进程,再开启子进程运行swoole服务。如果子进程想优雅退出,安装一个signalhandler,在退出前做一些操作。0){$fd=inotify_init();$watch_descriptor=inotify_add_watch($fd,'./src/',IN_MODIFY);$events=inotify_read($fd);posix_kill($pid,SIGTERM);fclose($fd);pcntl_wait($status);gotoRestart;}elseif($pid==0){\Church\Application::run();}else{exit(0);addSignal(SIGTERM,function()使用($loop){$loop->stop();});$server=newServer(function(ServerRequestInterface$request){returnnewResponse(200,array('Content-Type'=>'text/plain'),"HelloWorld1!\n");});$socket=new\React\Socket\Server(8080,$loop);$server->listen($socket);$loop->run();**///高性能HTTP服务器$http=new\Swoole\Http\Server("127.0.0.1",9501);$http->on("start",function($server){echo"Swoolehttp服务器启动于http://127.0.0.1:9501\n";});$http->on("request",function($request,$response){$response->header("Content-Type","text/plain");$response->end("HelloWorld1\n");});$http->start();}}个人认为这里最优雅的实现应该是使用GOTO,如果你有更好的请在评论区告诉我
