2010-12-14 17 views
0

Ich habe ein kleines Problem. Ich muss ein Skript ausführen, das 5000 URL in PHP ausführt.Führen Sie mehrere URL

$con = mysql_connect("localhost","user","psswd"); 

if (!$con) { 
    die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db('db_name', $con); 

print "connected"; 

$result = mysql_query ("SELECT name, uid FROM obinndocusers"); 

// I need to execute that url for each user 
while ($row = mysql_fetch_array($result)) { 
     header (Location http:xxxxxxxx?q=user/" . $row['uid'] . "/edit&destination=admin/user/user); 
} 

Irgendeine Idee ??

Thx.

Antwort

2

Verwendung CURL

LIKE:

$ch = curl_init(); 
while ($row = mysql_fetch_array($result)) { 

// set URL and other appropriate options 
curl_setopt($ch, CURLOPT_URL, "http://www.example.com?q=user/" . $row['uid'] . "/edit&destination=admin/user/user"); 
curl_setopt($ch, CURLOPT_HEADER, 0); 

// grab URL and pass it to the browser 
curl_exec($ch); 
} 
// close cURL resource, and free up system resources 
curl_close($ch); 
0

Verwenden cURL

<?php 
// create a new cURL resource 
$ch = curl_init(); 

// set URL and other appropriate options 
curl_setopt($ch, CURLOPT_URL, "http:xxxxxxxx?q=user/" . $row['uid'] . "/edit&destination=admin/user/user"); 
curl_setopt($ch, CURLOPT_HEADER, 0); 

// grab URL and pass it to the browser 
curl_exec($ch); 

// close cURL resource, and free up system resources 
curl_close($ch); 
?> 
0

Erste Sache: header() ist eine primitive http-Header-Browser zu senden. Es muss vor irgendein stdout Ausgang (wie 'Druck' oder 'Echo') genannt werden.

Zweite Sache: "Location:" Header wird Ihren Browser anweisen, auf diese URL umzuleiten. Sie können nicht mehr als eine URL angeben.

Wenn Sie Ihr Skript für HTTP-Abfragen benötigen, verwenden Sie curl oder fopen, und rufen Sie Ihr Skript nicht über Ihren Browser auf.

0

Der beste Weg wäre mit CURL (siehe andere Antwort von Haim Evgi), aber wenn der Server nicht die Curl-Erweiterung hat, dann wird dies auch funktionieren.

<? 
$con = mysql_connect("localhost","user","psswd"); 

if (!$con) { 
    die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db('db_name', $con); 

print "connected"; 

$result = mysql_query ("SELECT name, uid FROM obinndocusers"); 

// I need to execute that url for each user 
while ($row = mysql_fetch_array($result)) { 
     file_get_contents("http:xxxxxxxx?q=user/" . $row['uid'] . "/edit&destination=admin/user/user"); 
} 
Verwandte Themen