Sign in

Hope to add a coroutine ID to get onrequest, so as to facilitate the development of helper functions.

Rufus_12 edited in Fri, 01 Jul 2022

PHP's other frameworks are all one process processing a request. So there are a lot of short global helper functions. For example, DB model input and so on. However, it is not easy to implement assistant function when a request of swoole is completed in a coroutine. Hope to add a coroutine ID to get onrequest. This allows you to implement helper functions.


function getRequestID(){
    return co::getCid(); //这里希望有新的函数
function model(){
    global staticReqs;
$server = new Swoole\Http\Server('', 9501, SWOOLE_BASE);

$server->on('Request', function($request, $response) {
   $db=new Swoole\Coroutine\MySQL();
    //直接调用 函数不传参数model()

3 Replies
commented on Fri, 01 Jul 2022

Some of this function are spoolecoroutine:: getuid(); return to the current coroutine ID

commented on Fri, 01 Jul 2022


commented on Sat, 02 Jul 2022

If getuid () is called in a function (not a class method), if the function is called in the subfield, the ID obtained is not the onrequest ID. Of course, if you calculate well, there is a way to get the parent coroutine ID. But there's a lot of code. It's easy to make mistakes.

lock This question has been locked and the reply function has been disabled.