Applications/YourApp/start_businessworker.php代码:
<?php
...
require_once __DIR__ . '/../../vendor/autoload.php';
$worker = new BusinessWorker();
$worker->name = 'YourAppBusinessWorker';
$worker->count = 4;
$worker->registerAddress = '127.0.0.1:1238';
$worker->reloadable = true;
$worker->onWorkerStart = function($worker) {
require __DIR__ . '/../Trans/Trans.php'; //动态加载
};
if(!defined('GLOBAL_START'))
{
Worker::runAll();
}
在Events.php的onMessage()中测试:
public static function onMessage($client_id, $message)
{
Trans::test($message);
}
Trans.php 代码:
<?php
namespace Applications\Trans;
class Trans
{
public static function test($msg){
if($msg){
echo "\n$msg!----------------%%&";
}
}
}
可能是开了opcache。
运行
php -i | grep opcache.enable_cli
如果显示为on
,打开 php.ini 将opcache.enable_cli
其修改为 0。restart重启再试下。
高人!问题解决了,非常感谢!