设置全局CURL超时 [英] Set global CURL timeout

查看:73
本文介绍了设置全局CURL超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用专有的第三方Drupal模块,该模块通过curl查询第三方服务。最近该服务有点麻烦,这使我的页面加载减慢了很多,当我有很多流量时,我遇到的是max_connections。

I am using a proprietary, 3rd party Drupal module that queries a 3rd party service via curl. The service has been a bit flakey lately, which is slowing my page loads a lot and when I've got a lot of traffic I am hitting max_connections.

这个扩展查询不是至关重要的,但足够重要的是,我不能只删除该模块。暂时,我通过修补模块以向请求添加curl超时来对其进行修复:

The information that this extension queries is not vital, but it is important enough that I can't just remove the module. For the time being, I fixed it by patching the module to add a curl timeout to the request:

curl_setopt($ch, CURLOPT_TIMEOUT, 1);

但是,我不想保留该hack,因为它会在下一个消失

However, I don't want to leave the hack in place because it'll disappear on the next update and since the problem is intermittent it won't show up in testing.

是否可以通过php.ini设置或通过以下方式在全局范围内设置超时?代码(我可以将其放入自定义模块中)?

Is there any way to set the timeout globally in a php.ini setting or in PHP via code (that I could drop in a custom module)?

感谢任何帮助,

谢谢

推荐答案

PHP的CURL使用php.ini设置 default_socket_timeout 。默认值为60,单位为秒。

PHP's CURL uses the php.ini setting default_socket_timeout. The default value is 60, the unit is seconds.

这篇关于设置全局CURL超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆