Hello,
I have a simple script that gets data from a mysql database and runs a process for each item selected from the database using the while command. I wanted to find out if it is possible to run a section of the script multiple times at the same time with control of how many children processes it runs at once. I belive it's called forking but I am still new to php and have no idea on where to begin or if it's easily possible.
Here's my current script. It's still a work in progress but should give you an idea of what I'm trying to accomplish.
PHP Code:
<?
//Database Connection
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM su";
$result=mysql_query($query);
$num=mysql_numrows($result);
$j=0;
while ($j < $num) {
$address=mysql_result($result,$j,"address");
$email=mysql_result($result,$j,"email");
$lr=mysql_result($result,$j,"lr");
//I want this section to run multiple times at the same time
$fsock = fsockopen("$address", 80, $errno, $errstr, 5);
if ($errno == "0") {
$query = "UPDATE su SET success = success+1, lr = 'up' WHERE address = '$address'";
fclose($fsock);
if ($lr == "dn") {
$subject="Site back online";
$msg="Your Server Appears To Be Back Online. The address $address is now reachable.";
$mailheaders="From: Server Report";
mail ($email, $subject, $msg, $mailheaders);
}
}
else {
$query = "UPDATE su SET failed = failed+1, lr = 'dn' WHERE address = '$address'";
if ($lr == "up") {
$subject="Site not responding";
$msg="Your Server Appears To Be Offline. The address $address was unreachable. You will recive a e-mail when the site is again reachable.";
$mailheaders="From: Server Report";
mail ($email, $subject, $msg, $mailheaders);
}
}
mysql_query($query);
//End PHP fork process?
++$j;
}
mysql_close();
?>
If you have any suggestions or a good tutorial on this subject, that would be a great help!
Thank you.