执行多个url

时间:2010-12-14 12:44:30

标签: php

我有点问题。我需要执行一个在php中执行5000 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);
}

任何想法??

THX。

4 个答案:

答案 0 :(得分:2)

使用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);

答案 1 :(得分:0)

使用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);
?>

答案 2 :(得分:0)

首先: header()是将http标头发送到浏览器的原语。它必须在之前被称为任何标准输出(如'print'或'echo')。

第二件事:“Location:”标题会告诉您的浏览器重定向到该URL。您不能指定多一个网址。

如果您需要脚本执行http查询,请使用curlfopen,不要在浏览器中调用脚本。

答案 3 :(得分:0)

最好的方法是使用CURL(参见Haim Evgi的其他答案),但如果服务器没有curl扩展名,那么这也可以。

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