国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

Gatewayworker的多個Event如何使用全局變量?

EricWen
class Events
{
    static $receiver = null;

    public static function onWorkerStart($businessWorker)
    {
        $reboot = Robot::getInstance();
    }

同時在start_businesswork.php有如下測試代碼

$inner_text_worker = new Worker('Text://0.0.0.0:5678');
$inner_text_worker->onMessage = function ($connection, $buffer) {
    Robot::getInstance()
};
$inner_text_worker->listen();

Robot主要代碼

    protected function __construct()
    {
        echo "創(chuàng)建robot類\n";
    }

    public static function getInstance()
    {
        static $_instance = null;
        if ($_instance === null) {
            $_instance = new Robot();
        }
        return $_instance;
    }

測試發(fā)現(xiàn),Robot類創(chuàng)建了兩次,說明數(shù)據(jù)不能在多個Event中共享?

5940 1 0
1個回答

damao

開了兩個進程?
兩個進程的話會這樣,是正常的

  • EricWen 2017-03-07

    是的,開了4個進程,期望是在單機上面實現(xiàn)全局變量共享。

  • damao 2017-03-07

    每個進程都會運行onWorkerStart,所以會執(zhí)行多次。

年代過于久遠,無法發(fā)表回答
??