国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

php使用goto實現自動重啟swoole、reactphp、workerman服務的代碼

瀏覽:135日期:2022-09-10 18:34:28

在平時使用swoole進行開發中,常常遇到這種問題,改了代碼之后,手動ctrl+c中斷服務,再敲命令重啟服務。頻繁地重啟,感覺心很累。

php提供了inotify擴展,調用linux的inotify系統調用,監控文件的變化.

這時候就產生了一個想法,我開一個主進程監控文件變化,再開一個子進程運行swoole服務。主進程監聽到文件變化之后,干掉子進程,然后再開一個子進程運行swoole服務. 子進程如果想優雅地退出,安裝個信號處理器,在退出之前做一些操作。

<?php//index.phprequire ’./vendor/autoload.php’;Restart:$pid = pcntl_fork();if ($pid > 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); goto Restart;} elseif ($pid == 0) { ChurchApplication::run();} else { exit(0);}

<?phpnamespace Church;/**use PsrHttpMessageServerRequestInterface;use ReactHttpResponse;use ReactHttpServer;**/class Application{ public static function run() { /** $loop = ReactEventLoopFactory::create(); $loop->addSignal(SIGTERM, function() use ($loop) { $loop->stop(); }); $server = new Server(function (ServerRequestInterface $request) { return new Response(200,array( ’Content-Type’ => ’text/plain’),'Hello World1!n' ); }); $socket = new ReactSocketServer(8080, $loop); $server->listen($socket); $loop->run(); **/ //高性能HTTP服務器 $http = new SwooleHttpServer('127.0.0.1', 9501); $http->on('start', function ($server) { echo 'Swoole http server is started at http://127.0.0.1:9501n'; }); $http->on('request', function ($request, $response) { $response->header('Content-Type', 'text/plain'); $response->end('Hello World1n'); }); $http->start(); }}

個人覺得這里最優雅的實現方式應該是用GOTO了。

到此這篇關于php使用goto實現自動重啟swoole、reactphp、workerman服務的代碼的文章就介紹到這了,更多相關php自動重啟swoole、reactphp、workerman服務內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: PHP
相關文章:
主站蜘蛛池模板: 黔东| 苍溪县| 万全县| 乌兰察布市| 磐安县| 东台市| 九寨沟县| 孟村| 于都县| 汉中市| 凤庆县| 凤冈县| 康马县| 喜德县| 新源县| 谢通门县| 福鼎市| 武川县| 开化县| 望城县| 荆门市| 磴口县| 英德市| 奈曼旗| 明溪县| 永川市| 泌阳县| 广河县| 静海县| 池州市| 黄石市| 泸定县| 道孚县| 泸西县| 洞头县| 瓦房店市| 友谊县| 宜兴市| 成安县| 连平县| 滨州市|