dongtuo0828 2011-03-08 10:44
浏览 45

PHP中的Sleep命令返回非零值

I have a script, that is run as a part of my module in Drupal. In this module, I use cURL functions to request html page from a remote website, then I parse the html content and write it to my database. I wanted to have a delay between every request that I do to the remote server, hence I added sleep() in my PHP script.

function get_me_data()
{
  for( 15 iterations)
  {
    $html  =  file_get_contents($search_url);
    //parse html contents
    $delay  = mt_rand($interval1,$interval2); // interval1 = 0 , interval2=30
    $retval = sleep($delay);
  }
}
  1. function get_me_data() is initiated by cron job(hook_cron implemented in .module file).
  2. I have also tried to flush streams before the usage of sleep command. used flush(); ob_flush();fflush(filepointer); ob_implicit_flush(true)

It so happens that after 4-5 iterations, sleep() command returns NON ZERO value. the script aborts in the next iteration when sleep() is called

Let me know, if I am overlooking any aspect of sleep() here. I am using, PHP version 5.3 & Drupal 6

  • 写回答

1条回答 默认 最新

  • dongxie3963 2011-03-08 10:49
    关注

    According to the docs http://php.net/manual/en/function.sleep.php can return non zero values.

    If the call was interrupted by a signal, sleep() returns a non-zero value. On Windows, this value will always be 192 (the value of the WAIT_IO_COMPLETION constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.

    A comment in the sleep uses time_sleep_until() because it doesn't get interrupted.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度