亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

php使用goto實(shí)現(xiàn)自動(dòng)重啟swoole、reactphp、workerman服務(wù)的代碼

 更新時(shí)間:2020年04月13日 16:25:07   作者:church  
這篇文章主要介紹了php使用goto實(shí)現(xiàn)自動(dòng)重啟swoole、reactphp、workerman服務(wù)的方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

在平時(shí)使用swoole進(jìn)行開發(fā)中,常常遇到這種問(wèn)題,改了代碼之后,手動(dòng)ctrl+c中斷服務(wù),再敲命令重啟服務(wù)。頻繁地重啟,感覺心很累。

php提供了inotify擴(kuò)展,調(diào)用linux的inotify系統(tǒng)調(diào)用,監(jiān)控文件的變化.

這時(shí)候就產(chǎn)生了一個(gè)想法,我開一個(gè)主進(jìn)程監(jiān)控文件變化,再開一個(gè)子進(jìn)程運(yùn)行swoole服務(wù)。主進(jìn)程監(jiān)聽到文件變化之后,干掉子進(jìn)程,然后再開一個(gè)子進(jìn)程運(yùn)行swoole服務(wù). 子進(jìn)程如果想優(yōu)雅地退出,安裝個(gè)信號(hào)處理器,在退出之前做一些操作。

<?php

//index.php

require './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) {
  \Church\Application::run();
} else {
  exit(0);
}
<?php
namespace Church;

/**
use Psr\Http\Message\ServerRequestInterface;
use React\Http\Response;
use React\Http\Server;
**/

class Application
{
  public static function run()
  {
  /**
    $loop = \React\EventLoop\Factory::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 \React\Socket\Server(8080, $loop);
    $server->listen($socket);

    $loop->run();
  **/
    //高性能HTTP服務(wù)器
    $http = new \Swoole\Http\Server("127.0.0.1", 9501);

    $http->on("start", function ($server) {
      echo "Swoole http server is started at http://127.0.0.1:9501\n";
    });

    $http->on("request", function ($request, $response) {
      $response->header("Content-Type", "text/plain");
      $response->end("Hello World1\n");
    });

    $http->start();

  }
}

個(gè)人覺得這里最優(yōu)雅的實(shí)現(xiàn)方式應(yīng)該是用GOTO了。

到此這篇關(guān)于php使用goto實(shí)現(xiàn)自動(dòng)重啟swoole、reactphp、workerman服務(wù)的代碼的文章就介紹到這了,更多相關(guān)php自動(dòng)重啟swoole、reactphp、workerman服務(wù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論