From 34fc1ebb8b8505a8a24f27291ff36e3857ead4de Mon Sep 17 00:00:00 2001 From: flxxyz Date: Wed, 15 Aug 2018 16:17:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=B8=8E=E8=AF=B4=E6=98=8E?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++++-- src/Server.php | 7 +++++-- src/common/Swoole.php | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b50489d..02d38a6 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ ## 介绍 一个基于swoole的封装程序 -## 配置项 +## 实例 ```php -return [ +$config = [ 'timezone' => 'Asia/Shanghai', 'tick_interval_timer' => 30, //秒 'websocket' => [ @@ -54,6 +54,9 @@ return [ 'handler' => '', ], ]; + +$server = new \swoole_websocket_and_tcp_and_udp\Server($config); +$server->run(); ``` ## 任务 diff --git a/src/Server.php b/src/Server.php index bfcbfd8..0cb1bab 100644 --- a/src/Server.php +++ b/src/Server.php @@ -97,7 +97,6 @@ public function __construct($config) $this->otherConfig[$name] = $item; } -// var_dump($this->otherConfig);exit(1); $host = $this->primaryConfig['host']; $port = $this->primaryConfig['port']; @@ -237,7 +236,11 @@ public function Start(\swoole_http_server $server) $this->setProcessName('master process'); if (version_compare(\swoole_version(), '1.10.4', '>=')) { - file_put_contents($this->config['pid_file'], $server->master_pid); + if (isset($this->config['pid_file'])) { + if (is_dir(dirname($this->config['pid_file']))) { + file_put_contents($this->config['pid_file'], $server->master_pid); + } + } } } diff --git a/src/common/Swoole.php b/src/common/Swoole.php index 6c6d30e..bc05777 100644 --- a/src/common/Swoole.php +++ b/src/common/Swoole.php @@ -12,7 +12,7 @@ public function checkSwoole($version = '1.10.4') } //exec("php --ri swoole | grep Version | awk '{print $3}'"); - if(!version_compare(\swoole_version(), $version, '<')) { + if(!version_compare(\swoole_version(), $version, '>=')) { throw new \Exception("swoole扩展版本小于{$version}"); } }