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'; //動態(tài)加載
};
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!----------------%%&";
}
}
}