在laravel锻造和宅基地上慢慢下来

rap*_*2-h 5 php curl laravel guzzle laravel-forge

我不明白为什么在laravel forge和laravel宅基地上的guzzle请求真的很慢.我没有更改锻造和宅基地的默认服务器配置.

像这样的每个简单的请求......

$client = new GuzzleHttp\Client();
$response = $client->get('path-to-my-api');
Run Code Online (Sandbox Code Playgroud)

...大约需要150ms(在宅基地和锻造处).这附加在每个请求(相同的网络或互联网)上.我读了一些关于guzzle的帖子,对于每个用户来说似乎都非常快,但对我来说却不是.

版本:

  • curl 7.35.0(x86_64-pc-linux-gnu)libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3
  • PHP版本5.6.0
  • Guzzle 5.1.0

真的很奇怪的是,当我这样做时(异步)......

$req = $client->createRequest('GET', 'path-to-my-api', ['future' => true]);

$client->send($req)->then(function ($response) {
});
Run Code Online (Sandbox Code Playgroud)

......大约需要10毫秒.这很好,但我不明白为什么.而且我不想执行异步请求.

也许我的时间测量是错误的,但我认为这是好的:我使用这样的PHP调试栏:

// .....

// synch
Debugbar::startMeasure('synch','SYNCH Request');
$response = $client->get('path-to-my-api');
Debugbar::stopMeasure('synch');

// asynch
Debugbar::startMeasure('asynch','ASYNCH Request');
$req = $client->createRequest('GET', 'path-to-my-api', ['future' => true]);

$client->send($req)->then(function ($response) {
    Debugbar::stopMeasure('asynch');
});
Run Code Online (Sandbox Code Playgroud)

我知道回答这个问题并不容易(因为它含糊不清),但我现在还不知道:(.如果你愿意,我可以编辑它.非常感谢.

inf*_*iac 0

Guzzle 不能慢——它只是一个库。您的同步请求可能需要更长的时间,因为您的 API 需要很长时间才能响应,而您的异步请求似乎更快,因为它在收到响应之前不会阻塞网络。

尝试直接在浏览器中调用 API 或在终端中使用 cURL - 您可能会发现存在延迟。