Forum Moderators: coopster

Message Too Old, No Replies

Website Ping Script W/Email Notification - Help

website ping script

         

ga51279

12:32 am on Aug 16, 2008 (gmt 0)

10+ Year Member



I am trying to get my code to pull data from my database. Basically a list of urls and emails. The below script is to scan each url and if it is down to send an email letting the user know. It is scanning correctly. The issue I am having is, it is only sending an email to the most recent entry in to the database. It will not continue on and send emails to other website owners that are down pulled from mysql.

I believe the problem is going to be the end of the script where it starts the email process and not the actual scan process. Any help would be grateful.


$result = mysql_query("SELECT urls,emails FROM sites");
while ($row = mysql_fetch_array($result)) {
$link=$row['url'];
$email=$row['email'];
//check for port number, default is 80
$s_link = str_replace("::", ":", $link);
}
list($addr,$port)= explode (':',"$s_link");
if (empty($port)){
$port = 80;
}
//Test the server connection
$churl = @fsockopen(server($addr), $port, $errno, $errstr, 20);
if (!$churl){
//echo $errstr;
header("Location: $dead");
}
else {
header("Location: $live");
}
function server($addr){
if(strstr($addr,"/")){$addr = substr($addr, 0, strpos($addr, "/"));}
return $addr;
}
$to = $email;
$from ="Site Monitor";
$subject = "$link Is Down";
$body = "MY Message";
if ($errstr)
mail($to, $subject, $body)

eeek

10:30 pm on Aug 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



while ($row = mysql_fetch_array($result)) {
$link=$row['url'];
$email=$row['email'];
//check for port number, default is 80
$s_link = str_replace("::", ":", $link);
}

This just runs through the results and replaces $email and $link each time. In other words you aren't saving anything but the last row.

ga51279

11:17 pm on Aug 16, 2008 (gmt 0)

10+ Year Member



I have searched the net in regards to this still have not found a solution. Can you please explain with the script posted above on how to make it continue on to the next row after it scans the url in the first row to see if it is down or not. please eeek?

ga51279

1:06 am on Aug 17, 2008 (gmt 0)

10+ Year Member



Well I have trimmed the code down a little. Still works as before, last row issue. I understand that I have not fixed the issue with the new code, just wanted to clean it up a little for what I am needing.

<?php
include 'includes/opendb.php';
$result = mysql_query("SELECT * FROM sites");
while ($row = mysql_fetch_array($result)) {

$link=$row["url"];
$email=$row["email"];
$port="80";
$s_link = str_replace("::", ":", $link);
list($addr,$port)= explode (':',"$s_link");
//Test the server connection
$churl = fsockopen($link,$port,$errno,$errstr, 20);
} if (!$churl){
$to = $email;
$from ="Site Monitor";
$subject = "$link Is Down";
$body = "My Message";
mail($to, $subject, $body);
}
else
die ()
?>

eeek

1:38 am on Aug 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



while ($row = mysql_fetch_array($result)) {

$link=$row["url"];
$email=$row["email"];
$port="80";
$s_link = str_replace("::", ":", $link);
list($addr,$port)= explode (':',"$s_link");
//Test the server connection
$churl = fsockopen($link,$port,$errno,$errstr, 20);
} <--you closed out the loop right here if (!$churl){

ga51279

1:48 am on Aug 17, 2008 (gmt 0)

10+ Year Member



Works like a charm, thank you for your help eeek :)

Cheers


<?php
include 'includes/opendb.php';
$result = mysql_query("SELECT * FROM sites");
while ($row = mysql_fetch_array($result)) {
$link=$row["url"];
$email=$row["email"];
$port="80";
$s_link = str_replace("::", ":", $link);
list($addr,$port)= explode (':',"$s_link");
//Test the server connection
$churl = fsockopen($link,$port,$errno,$errstr, 20);
if (!$churl)
$to = $email;
$from ="Site Monitor";
$subject = "$link Is Down";
$body = "My Message";
mail($to, $subject, $body);
}
?>

eeek

3:56 am on Aug 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



BTW, a better way to check the servers is to use curl to do a "HEAD /" request.