CardellCr
CardellCr

Reputation: 33

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_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);
}

Any idea??

Thx.

Upvotes: 0

Views: 1520

Answers (4)

Oliver O'Neill
Oliver O'Neill

Reputation: 1254

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

Upvotes: 0

Patrick
Patrick

Reputation: 2405

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.

Upvotes: 0

Christophe Ebl&#233;
Christophe Ebl&#233;

Reputation: 8161

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

Upvotes: 0

Haim Evgi
Haim Evgi

Reputation: 125486

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

Upvotes: 2

Related Questions