Brian
Brian

Reputation: 47

Why my curl request never stop?

I wanna get 2 years of data while execute php files. But the problem is, curl request never stop for one occurence, end if i put that :

curl_setopt($ch, CURLOPT_TIMEOUT, 30);

It's work but i wait 30sec, in my navigator, i wait few sec for execute the file, why my script never stop?

The code :

<?php
  $dateDeb = '2010-07-23';
  $dateFin = '2012-07-23';

  $debut_mois = 07;
  $debut_jour = 23;
  $debut_annee = 2010;
  $fin_mois = 07;
  $fin_jour = 23;
  $fin_annee = 2012;
$dates=array();
   $debut_date = mktime(0, 0, 0, $debut_mois, $debut_jour, $debut_annee);
   $fin_date = mktime(0, 0, 0, $fin_mois, $fin_jour, $fin_annee);

    for($i = $debut_date; $i <= $fin_date; $i+=86400)
    {
            $dates[]=date("Y-m-d",$i);
    }



foreach($dates as $date){

    $cron1='http://ndd.com/admin/api/xiti/bot-lien_sponsorisees/'.$date;
    $cron2='http://ndd.com/admin/api/xiti/bot-affiliation/'.$date;
    $cron3='http://ndd.com/admin/api/xiti/bot-analytics/'.$date;

    echo $date." : EN COURS ... ";

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $cron1); 
    curl_setopt($ch, CURLOPT_USERPWD, 'user:pass');
   // curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_exec($ch); 
    curl_close($ch);


    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $cron2); 
    curl_setopt($ch, CURLOPT_USERPWD, 'user:pass');
    //curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_exec($ch); 
    curl_close($ch);

    echo $date." : OK \n";

    }

Upvotes: 0

Views: 1944

Answers (2)

Waleed Khan
Waleed Khan

Reputation: 11467

You have two years of days. Each of those will make a new request, and new requests don't have any knowledge of old requests or how long those requests took. If you want to stop execution after a certain time, you can use set_time_limit:

set_time_limit(30);

Upvotes: 1

arosolino
arosolino

Reputation: 1077

It never stops because your looping through 2 years worth of dates, which is 730 days.

So you are issuing 730 CURL commands, and with the timeout that can equate to 730 * 30 = 21900 max seconds of processing.

Actually I see you are issuing two CURL commands, so 21900 * 2 = 43800 max seconds of processing.

Upvotes: 1

Related Questions