简体   繁体   English

如何诊断长期运行的PHP curl请求

[英]How to diagnose long-running PHP curl requests

Our PHP web app makes a series of curl requests to APIs in response to certain requests. 我们的PHP网络应用程序响应某些请求向API发出了一系列卷曲请求。 We're debugging a problem where the request occasionally times out after 30 seconds with a 503 response code... we're pretty sure it's because one (or two) of the curl requests is taking too long. 我们正在调试一个问题,该请求在30秒后偶尔会用503响应代码超时……我们可以确定这是因为一个(或两个)curl请求花费的时间太长。

In an effort to diagnose which curl requests are the problem, we'd like to log or track the individual requests. 为了诊断出哪些卷曲请求是问题,我们希望记录或跟踪各个请求。 We're hosting the app on a Heroku Cedar instance with the Logentries add-on and we also use New Relic, but neither tools seem to offer an option to log/track the individual curl s. 我们使用Logentries插件将应用程序托管在Heroku Cedar实例上,并且我们也使用New Relic,但是这两个工具似乎都没有提供记录/跟踪单个curl的选项。 How do we do this? 我们如何做到这一点?

I know we could set variables with timestamps and log them manually... but suspect we'd be "reinventing the wheel." 我知道我们可以设置带有时间戳的变量并手动记录它们……但是怀疑我们会“重新发明轮子”。 What's the best way to do this, preferably without messing with our code base. 最好的方法是什么,最好不要弄乱我们的代码库。

You're going to need xdebug and code modifications to diagnose it. 您将需要xdebug和代码修改来对其进行诊断。 I guess you don't have to change much on the code but set 我想您不必在代码上进行太多更改,而是设置

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);  //set it to 0 for infinity
curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds, increase that 

also don't forget to enlarge time execution of php script self: 也别忘了扩大php脚本自身的执行时间:

`set_time_limit(0);//` to infinity for example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM