auto_reload
auto_reload copied to clipboard
为什么inotify执行热更新后,会将swoole的进程杀死了,导致需要手动重新启动swoole服务?
- server类
<?php
namespace WebIM;
use Swoole;
use SPF\Filter;
use SPF;
use Swoole\Coroutine as Co;
use Swoole\Coroutine\Http\Server as CoHttpServer;
class HttpServer
{
protected $users;
protected $config;
protected $connections;
protected $redis;
protected $db;
/**
* 上一次发送消息的时间
* @var array
*/
protected $lastSentTime = array();
const MESSAGE_MAX_LEN = 1024; //单条消息不得超过1K
const WORKER_HISTORY_ID = 0;
const PREFIX = 'webim';
function __construct($config = array())
{
$this->config = $config;
}
function run()
{
go(function (){
$config = $this->config;
$server = new CoHttpServer($config['server']['host'], $config['server']['port']);
$server->handle('/', function (Swoole\Http\Request $request, Swoole\Http\Response $response){
$response->end('Hello world11');
});
$server->start();
});
}
}
- 以下是inotity的deamon.php
<?php
require __DIR__.'/src/Swoole/ToolKit/AutoReload.php';
$kit = new Swoole\ToolKit\AutoReload(1989);
$kit->watch(__DIR__.'/../webim-2.0');
$kit->run();
- 热更新执行完毕后,再另外一个窗口就弹出:
[1]+ User defined signal 1 nohup php server.php的信息,再通过命令:ps -aux | grep php查运行中的php进程时,发现server.php的程序已经被杀死了,请问如何能做不杀死进程对swoole的代码进行热更新?
[913]=>
array(4) {
["wd"]=>
int(1829)
["mask"]=>
int(32768)
["cookie"]=>
int(0)
["name"]=>
string(0) ""
}
[914]=>
array(4) {
["wd"]=>
int(1830)
["mask"]=>
int(32768)
["cookie"]=>
int(0)
["name"]=>
string(0) ""
}
}
--------------------
root@bda0488a9612:/var/www/webim-2.0# ps -aux | grep php
root 1 0.0 1.3 92732 27924 ? Ss 14:42 0:01 php-fpm: master process (/usr/local/etc/php-fpm.conf)
www-data 7 0.0 0.3 92732 7180 ? S 14:42 0:00 php-fpm: pool www
www-data 8 0.0 0.3 92732 7180 ? S 14:42 0:00 php-fpm: pool www
root 1987 0.0 1.4 92776 29352 pts/0 S+ 17:28 0:00 php daemon.php
root 1989 0.1 1.4 94956 29172 pts/1 S 17:43 0:00 php server.php
root 1991 0.0 0.0 3080 876 pts/1 S+ 17:43 0:00 grep php
root@bda0488a9612:/var/www/webim-2.0# ps -aux | grep php
root 1 0.0 1.3 92732 27924 ? Ss 14:42 0:01 php-fpm: master process (/usr/local/etc/php-fpm.conf)
www-data 7 0.0 0.3 92732 7180 ? S 14:42 0:00 php-fpm: pool www
www-data 8 0.0 0.3 92732 7180 ? S 14:42 0:00 php-fpm: pool www
root 1992 0.5 1.4 92776 29296 pts/0 S+ 17:44 0:00 php daemon.php
root 1994 0.0 0.0 3080 888 pts/1 S+ 17:45 0:00 grep php
[1]+ User defined signal 1 nohup php server.php
root@bda0488a9612:/var/www/webim-2.0#