Events::onWorkerStart
說明:
void Event::onWorkerStart(BusinessWorker $businessWorker);
(要求Gateway版本>=2.0.4)
當(dāng)businessWorker進(jìn)程啟動時(shí)觸發(fā)。每個(gè)進(jìn)程生命周期內(nèi)都只會觸發(fā)一次。
可以在這里為每一個(gè)businessWorker進(jìn)程做一些全局初始化工作,例如設(shè)置定時(shí)器,初始化redis等連接等。
注意:$businessworker->onWorkerStart
和Event::onWorkerStart
不會互相覆蓋,如果兩個(gè)回調(diào)都設(shè)置則都會運(yùn)行。
不要在onWorkerStart內(nèi)執(zhí)行長時(shí)間阻塞或者耗時(shí)的操作,這樣會導(dǎo)致BusinessWorker無法及時(shí)與Gateway建立連接,造成應(yīng)用異常(SendBufferToWorker fail. The connections between Gateway and BusinessWorker are not ready
錯(cuò)誤)。
參數(shù)
$businessWorker
businessWorker進(jìn)程實(shí)例
返回值
無返回值,任何返回值都會被視為無效的
onWorkerStart范例
use \GatewayWorker\Lib\Gateway;
class Events
{
public static function onWorkerStart($businessWorker)
{
echo "WorkerStart\n";
}
}