douban5644 2014-10-22 12:26
浏览 31

php如何在脚本中添加暂停?

We are have a code:

<?php 
function cURL_AutonavigatorRu($level = false, $model_id = false){
    #http://www.autonavigator.ru
    $ch = curl_init('http://www.autonavigator.ru/dispatcher.pl');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36"); 
    $headers = array
    (
        'Accept: application/json',
        'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4',
        'Accept-Encoding: gzip,deflate',
        'Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7'
    ); 

    curl_setopt($ch, CURLOPT_HTTPHEADER,$headers); 
    curl_setopt($ch, CURLOPT_REFERER, "http://www.autonavigator.ru/my/offer_add/");

    if($level == '1'){
        curl_setopt($ch, CURLOPT_POSTFIELDS, 'class=list&method=make&show_all=1&vehicle=car&type=used');
    }
    elseif($level == '2' && $model_id){
        curl_setopt($ch, CURLOPT_POSTFIELDS, 'class=list&method=model&show_all=1&vehicle=car&type=used&make_id='.$model_id);
    }
    elseif($level == '3' && $model_id){
        curl_setopt($ch, CURLOPT_POSTFIELDS, 'class=list&method=modif&show_all=1&model_id='.$model_id);
    }
    else{
        curl_setopt($ch, CURLOPT_POSTFIELDS, 'class=list&method=modif&show_all=1&model_id='.$model_id);
    }

    curl_setopt($ch, CURLOPT_ENCODING , "gzip");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $result = curl_exec($ch);
    curl_close($ch);

    $json = json_decode(iconv("windows-1251","utf-8",$result), true);
    return $json['list'];
}


$ArrAuto = cURL_AutonavigatorRu('1');

foreach($ArrAuto as $auto) {

    echo $auto['value'].'<br>';


    //sleep(2);
    $AllModif1 = cURL_AutonavigatorRu('2',$auto["id"]);
    var_dump($AllModif1);
    echo '<br><br>----------------------------------<br><br>';

}

We are have problem - web site block curl and not give results for each $AllModif1 = cURL_AutonavigatorRu('2',$auto["id"]); in one time(in curl we get null).

Tell me please how make to pause the script that cycle foreach($ArrAuto as $auto) worked every 5 seconds?

P.S.: How make pause 4 secound between cycle?

P.P.S.: we are know about sleep() but i not get result with it see please prntscr.com/4ylm9y

  • 写回答

5条回答 默认 最新

  • doujieluo5875 2014-10-22 12:28
    关注

    Use sleep:

    foreach($ArrAuto as $auto){
      //Your amazing code here
    
      sleep(4);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图