Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webman使用easyhttp时,异步访问有问题 #1

Closed
leamus opened this issue Nov 9, 2022 · 12 comments
Closed

Webman使用easyhttp时,异步访问有问题 #1

leamus opened this issue Nov 9, 2022 · 12 comments

Comments

@leamus
Copy link

leamus commented Nov 9, 2022

代码类似这样:

public function test(Request $request)
{
    Http::getAsync('http://wisersportclub.com:8000', [], function (Response $response) {
        echo '异步请求成功,响应内容:' . $response->body() . PHP_EOL;
    }, function (RequestException $e) {
        echo '异步请求异常,错误码:' . $e->getCode() . ',错误信息:' . $e->getMessage() . PHP_EOL;
    });
    echo json_encode(['code' => 200, 'msg' => '请求成功'], JSON_UNESCAPED_UNICODE) . PHP_EOL;

    return json(['code' => 0, 'msg' => 'ok', 'data' =>$request->post('data')]);
}

public function test1(Request $request)
{
    $response = Http::get('http://wisersportclub.com:8000');
    echo '同步请求成功,响应内容:' . $response->body() . PHP_EOL;

    return json(['code' => 0, 'msg' => 'ok', 'data' =>$request->post('data')]);
}

出现问题:
访问test时,异步输出一直没有,此时如果访问一下test1,异步立刻输出,且同步也输出:

worker listen processes status
webman http://0.0.0.0:8100 2 [ok]
monitor none 1 [ok]
{"code":200,"msg":"请求成功"}
(此时一直不动,直到访问test1)
异步请求成功,响应内容:hello webman
同步请求成功,响应内容:hello webman
(再次访问test,仍然是这样)
{"code":200,"msg":"请求成功"}

请问是什么情况呢?

@yuanzhihai
Copy link
Owner

我这没问题啊

@leamus
Copy link
Author

leamus commented Nov 10, 2022

我这是webman最新的,c测试代码也没问题啊。。

@leamus
Copy link
Author

leamus commented Nov 10, 2022

测试环境windows

@yuanzhihai
Copy link
Owner

public function test(Request $request)
{
Http::getAsync('http://wisersportclub.com:8000', [], function (Response $response) {
echo '异步请求成功,响应内容:' . $response->body() . PHP_EOL;
}, function (RequestException $e) {
echo '异步请求异常,错误码:' . $e->getCode() . ',错误信息:' . $e->getMessage() . PHP_EOL;
})->wait();
echo json_encode(['code' => 200, 'msg' => '请求成功'], JSON_UNESCAPED_UNICODE) . PHP_EOL;

return json(['code' => 0, 'msg' => 'ok', 'data' =>$request->post('data')]);

}

增加 wait(); 等待获取

@leamus
Copy link
Author

leamus commented Nov 10, 2022

加wait虽然没问题,但这也相当于同步了吧。。

@leamus
Copy link
Author

leamus commented Nov 10, 2022

是不是因为不加wait,返回后导致上下文环境释放什么的未知原因呢?

@yuanzhihai
Copy link
Owner

是不是因为不加wait,返回后导致上下文环境释放什么的未知原因呢?

在切换其他方法路由的时候 异步就返回来了
这个我还没找到原因 在 fpm环境下是没问题的

@yuanzhihai
Copy link
Owner

群主有 http异步插件

@leamus
Copy link
Author

leamus commented Nov 10, 2022

好的,谢谢~

@leamus
Copy link
Author

leamus commented Nov 10, 2022

群主的http异步是哪个?

@yuanzhihai
Copy link
Owner

群主的http异步是哪个?

https://github.com/walkor/http-client

@leamus
Copy link
Author

leamus commented Nov 10, 2022

谢谢~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants