cURL - 如何禁用它请求响应
我使用 cURL 脚本将参数发布到我的其他网站上的页面作为客户端的更新,我的问题是我的curl 脚本在等待对一个网站的响应然后继续访问其他网站之前停止,即使一页时间需要很长时间才能进入下一个,我尝试使用curl_setopt将连接超时和超时设置为0,但这在我的问题的响应方面不起作用。那么,开始吧,在继续下一个服务器之前,如何停止curl 等待目标服务器的响应?
谢谢, 约翰
im using a cURL script to post parameters to pages on my others sites as a update for clients, my problem is that my curl script stops while its waiting from a response to one site before continuing on to the other sites, also if one page time outs it takes ages to get on to the next, ive tryed using curl_setopt to set connectiontimeout and timeout to 0 and that doesnt work on the responses side of my problem. So getting down to it, how do i stop curl waiting for a response from the target server before moving on to the next one?
Thanks,
John
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您应该检查响应,了解是否一切正常或再试一次。解决方案可能是一次运行多个curl请求: curl_multi_init ,如果您确实不想等待,请设置较小的超时(但不要太小,给一些时间来获取 DNS 记录并发送请求,尝试使用
CURLOPT_CONNECTTIMEOUT_MS
)并将CURLOPT_NOBODY
设置为true
(或将CURLOPT_CUSTOMREQUEST
设置为HEAD
),因此curl不会等待变得完整回复。Firstly, you should check response, to know if everything went OK or give a second try. Solution might be to run multiple curl request at once: curl_multi_init, and if you really don't want to wait, set small timeout (but not too small, give some time to fetch DNS record and send request, try with
CURLOPT_CONNECTTIMEOUT_MS
) and setCURLOPT_NOBODY
totrue
(orCURLOPT_CUSTOMREQUEST
toHEAD
), so curl won't wait to get whole response.