duanshang9426 2014-01-06 14:42
浏览 35

带有curl的简单html dom解析器在不同的URL上挂起太长时间

I use simple HTML DOM parser together with curl (I do not have a big experience with curl) and I try to figure out why is hanging on different URL requests long. I have been trying to log with verbose but I did not get back any useful information. It seems like is a Caching problem because after long response all my other requests are acting the same till I clear Browser Cache

str_get_html(get_data($target));

function get_data($url)
{
 $ch = curl_init();
 $timeout = 30;
 curl_setopt($ch,CURLOPT_URL,$url);
 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
 curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
 curl_setopt($ch, CURLOPT_USERAGENT, 'some useragent');
 $data = curl_exec($ch);
 curl_close($ch);
 return $data;
}
  • 写回答

1条回答 默认 最新

  • dqd54099 2014-01-06 16:27
    关注

    You are using CURLOPT_NOBODY curl option in your request. Are you sure what it does? It sends the HEAD request to the target url instead of the GET. There are lot of web servers available in the Internet which do accept the HEAD request and keep the request in stuck until the timeout occures. And this is what you are experiencing right now.

    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路