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

WorkerMan 和Swoole 一起用碰到的疑問

debugman

第一個Work mqWorker 里非得執(zhí)行 Swoole\Runtime::enableCoroutine(true);
不然onWorkerStart 就會阻塞執(zhí)行, 嘗試了很多種寫法都不行
在文件 開始 調(diào)用 enableCoroutine, 又會報錯
API must be called in coroutine
跟蹤了代碼,發(fā)現(xiàn)是調(diào)用unixsocket的函數(shù)報錯了, 感覺是調(diào)用了enableCorotine后, 阻塞函數(shù)都不能用了似的

目前我的示例代碼可以按照我的意愿執(zhí)行的, 但是比較惡心的是需要單獨調(diào)用enableCoroutine, 不能有滿意的解釋, 這個代碼不敢用到生產(chǎn)環(huán)境中.

mq_loop_recv 函數(shù)是我調(diào)用PHP rabbitmq 的循環(huán)收消息函數(shù)

$mqWoker = new Worker();

//啟動2個進程對外服務(wù)
$mqWoker->count = 1;

$mqWoker->onWorkerStart = function($mqWoker)
{
    printf("will Exec mq_loop_recv\n");
    Swoole\Runtime::enableCoroutine(true);
    go("mq_loop_recv");
    printf("will Exec mq_loop_recv over\n");
};

$threadWorker1 = new Worker();
$threadWorker1->onWorkerStart = function ($threadWorker1){

    go(function () {
       sleep(5);
       printf( "threadWorker1 is alive!\n" );
    });
};

$threadWorker2 = new Worker();
$threadWorker2->onWorkerStart = function ($threadWorker2){

    go(function () {
        sleep(5);
        printf( "threadWorker2 is alive!\n" );
    });
};
Worker::$eventLoopClass = 'Workerman\Events\Swoole';

//go(function ()  {
//    Worker::runAll();
//});

Worker::runAll();
3530 1 0
1個回答

debugman

我是希望用worman 來寫常駐服務(wù), 里面的協(xié)程可以實現(xiàn)主動調(diào)度, 不用來消息觸發(fā)

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