开发者

Execute multiple url

I have a little problem. I need to execute an script that execute 5000 URL in php.

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

if (!$con) {
  die('Could not connect: ' . mysql_error());
}
mysql_sele开发者_如何学编程ct_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);
}

Any idea??

Thx.


use 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);


Use 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);
?>


First thing: header() is a primitive to send http headers to browser. It must be called before any stdout output (like 'print' or 'echo').

Second thing: "Location: " header will tell your browser to redirect to that URL. You can not specify more that one URL.

If you need your script to do http queries, use curl or fopen, and do not call your script from your browser.


The best way would be with CURL (see other answer by Haim Evgi), but if the server doesn't have the curl extension, then this will also work.

<?
$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");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜