nasıl bir sabit zaman dilimi için bu döngü duraklatırım?

0 Cevap

Ben metin dosyasını okuyun ve API çağrısı yapmak ve sonra mySQL bu sonucu eklemek olacak bir dizi var. Dökme olarak çalıştırdığınızda, ancak API sunucudan yanıt yavaş ve sonuçları nedeniyle bu kadar çok boş geliyor. ne arıyorum alışkanlık boş sonuç almak çok api sunucudan sonucu almak için söylüyorlar 5 saniye her çağrı için bu döngü duraklatmak için bir yol yoktur.

Bu kod aşağıda

//connect to your database 
mysql_connect("localhost", "root", "password"); 
mysql_select_db("somedb"); 

//read your text file into an array, one entry per line 
$lines = file('filename.txt'); 

//loop through each website URL  
foreach ($lines as $website_url) { 

    //make the request to the compete API 
    $response = file_get_contents("http://apps.compete.com/sites/" . $website_url . "/trended/rank/?apikey=0sdf456sdf12sdf1"); 

    //decode the request 
    $response = json_decode($request); 

    //get the rank from the response 
    $rank = $response['something'];  

    //insert the website URL and its rank 
    mysql_query("INSERT INTO website_ranks (website_url, rank) VALUES ('" . mysql_real_escape_string($website_Url) . "', " . $rank . ")"); 

} 

0 Cevap