Dieter Raber: Sehr viele URL aus PHP-Skript aufrufen um API anzusprechen

Beitrag lesen

Hallo,

ein moeglicher Loesungsansatz waere ein Cronjob mit einem cURL Script. Das wuerde etwa so aussehen:

Shellscript:
php -f script.php, naeheres siehe hier

PHP-Script:

// Der Code kommt aus einer meiner Funktionen, den wirst du an deine Gegebenheiten anpassen muessen, mehr hierzu auf dieser Seite
function deine_curl_function($url) {
    $result    = false;
    $handle    = curl_init($uri);

if($handle) {
      curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($handle, CURLOPT_HEADER, 0);
      curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($handle, CURLOPT_TIMEOUT, 20);
      curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 10);
      curl_setopt($handle, CURLOPT_FRESH_CONNECT, 1);

//get the content
      $result = curl_exec ($handle);

//get the status header
      $status = curl_getinfo($handle, CURLINFO_HTTP_CODE);

//if we did not get a 200 http status, return false
      if($status != 200) {
        $result = false;
      }
      curl_close ($handle);

}
    return $result;
}

foreach($array_mit_urls as $url) {
  deine_curl_function($url);
  set_time_limit(20 oder so);
}

Das ist, wie gesagt, nur eine Denkansatz, bestimmt gibt es auch noch smartere Wege.

Gruss

Dieter