douke1891 2017-03-10 20:03
浏览 59
已采纳

PHP:设置超时的调用URL?

I want to call a certain URL in my PHP script and if I do not get a response after 10s, the script should just continue. Does anyone knows how I can do that?

I only found two ways. One is fopen(), which determinates my script if it doesn't get a return and curl which is just calling the URL without waiting/getting response?

But how can I say, try to get the content of the URL and if you do not get anything after 10s then continue and ignore the URL?

  • 写回答

1条回答 默认 最新

  • dsy48837 2017-03-10 20:28
    关注

    You can use curl.

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "url");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    $response = curl_exec($ch);
    curl_close($ch);
    

    If timeout is occurred - $response variable has boolean 'false' value.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试