使用GatewayWorker 进行开发,在Events.php文件的onMessage中修改了代码,然后 “php start.php reload [-d]” 发现新的代码并没有reload 。但本地的mac上又可以reload
restart 都可以
环境:
服务器: Centos + PHP7.2 + GatewayWorker 3.0.22
MAC : PHP7.2 + + GatewayWorker 3.0.22
public static function onMessage($client_id, $message)
{
self::addLog(PHP_EOL.'test-'.time().PHP_EOL);//新加
return Gateway::sendToClient($client_id, $message);
}
public static function addLog($msg = '',$level = 'info'){
$now = \DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''));
$msg = $now->format("Y-m-d H:i:s.u") . "\t" . $msg . PHP_EOL;
$fileName = 'app_'.date('Ymd').'_'.$level.'.log';
@file_put_contents($fileName,$msg,FILE_APPEND);
}
请问还有那些可能因素导致?感谢!
1、我是在onXXX内
https://www.workerman.net/q/1988
2、我关闭了服务器的opcache也不行
https://www.workerman.net/q/7459
3、根据以下我在Events.php的onWorkerStart打印了 var_dump(get_included_files());
发现文件被包含在里面,但是我看文档(https://www.workerman.net/doc/workerman/install/start-and-stop.html) 和1中举的例子应该可以被reload
https://www.workerman.net/q/6747
onWorkerStart打印了 var_dump(get_included_files()); 如果文件被包含在里面是不能热更新的。
你可以在Events.php 里输出调用栈,看下是哪个逻辑提前加载了Events.php 文件,Events.php 里代码结构类似
Exception: test in /data/www/app/barrage/Events.php:21
Stack trace:
0 /data/www/vendor/workerman/workerman/Autoloader.php(60): require_once()
1 [internal function]: Workerman\Autoloader::loadByNamespace('Events')
2 [internal function]: spl_autoload_call('Events')
3 /data/www/vendor/workerman/gateway-worker/src/BusinessWorker.php(226): is_callable('Events::onWorke...')
4 /data/www/vendor/workerman/workerman/Worker.php(2450): GatewayWorker\BusinessWorker->onWorkerStart(Object(GatewayWorker\BusinessWorker))
5 /data/www/vendor/workerman/gateway-worker/src/BusinessWorker.php(197): Workerman\Worker->run()
6 /data/www/vendor/workerman/workerman/Worker.php(1574): GatewayWorker\BusinessWorker->run()
7 /data/www/vendor/workerman/workerman/Worker.php(1416): Workerman\Worker::forkOneWorkerForLinux(Object(GatewayWorker\BusinessWorker))
8 /data/www/vendor/workerman/workerman/Worker.php(1390): Workerman\Worker::forkWorkersForLinux()
9 /data/www/vendor/workerman/workerman/Worker.php(557): Workerman\Worker::forkWorkers()
10 /data/www/start.php(37): Workerman\Worker::runAll()
看起来是框架的自动加载
Events.php的onWorkerStart里打印
var_dump(get_included_files());
包含Events.php是正常的。运行
ps auxf
看下是不是启动了多个gatewayWorker,访问到了另外一个gatewayWorker中。或者是不是分布式部署了,访问到了其它的服务器。
root 21641 0.0 0.1 591980 9600 ? S 07:50 0:00 _ WorkerMan: worker process BarrageGateway websocket://0.0.0.0:7272
root 21642 0.0 0.1 591980 9688 ? S 07:50 0:00 _ WorkerMan: worker process BarrageGateway websocket://0.0.0.0:7272
root 21643 0.0 0.1 591980 9856 ? S 07:50 0:00 _ WorkerMan: worker process BarrageGateway websocket://0.0.0.0:7272
root 21644 0.0 0.1 591980 9860 ? S 07:50 0:00 _ WorkerMan: worker process BarrageGateway websocket://0.0.0.0:7272
root 21647 0.0 0.1 591980 9156 ? S 07:50 0:00 _ WorkerMan: worker process BarrageRegister text://0.0.0.0:1236
root 30420 0.0 0.1 594204 11452 ? S 08:14 0:00 _ WorkerMan: worker process BarrageBusinessWorker none
root 30423 0.0 0.1 591980 9644 ? S 08:14 0:00 _ WorkerMan: worker process BarrageBusinessWorker none
root 30426 0.0 0.1 591980 9648 ? S 08:14 0:00 _ WorkerMan: worker process BarrageBusinessWorker none
root 30429 0.0 0.1 594200 11368 ? S 08:14 0:00 _ WorkerMan: worker process BarrageBusinessWorker none
我是一台服务器没有进行分布式,gateway和register都是127.0.0.1本地,只开了一个gatewayWorker 项目
看起来都是正常的
有可能还是opcache没关闭,执行
php -i | grep opcache.enable
看下opcache.enable_cli
是否关闭opcache.enable => Off => Off
opcache.enable_cli => Off => Off
opcache.enable_file_override => Off => Off
手动关闭了opcache,再次reload还是不行。
我的系统是Linux ip-xxxx.compute.internal 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux