Creating a ping uptime service with PHP?

Below I've written a simple PHP script that does what you ask. It pings a server, logs the result to a text file ("up" or "down"), and sends an email depending whether the previous result was up or down. To get it to run every five minutes, you'd need to configure a cron job to call the PHP script every five minutes.(Many shared web hosts allow you to set up cron jobs; consult your hosting provider's documentation to find out how.) Com"; //the address to test, without the "" $port = "80"; //Create a text file to store the result of the ping for comparison $db = "pingdata.

Txt"; if (file_exists($db)): $previous_status = file_get_contents($db, true); else: file_put_contents($db, "up"); $previous_status = "up"; endif; //Ping the server and check if it's up $current_status = ping($server, $port, 10); //If it's down, log it and/or email the owner if ($current_status == "down"): echo "Server is down! "; file_put_contents($db, "down"); if ($previous_status == "down"): mail($email, "Server is down", "Your server is down."); echo "Email sent. "; endif; else: echo "Server is up!

"; file_put_contents($db, "up"); if ($previous_status == "down"): mail($email, "Server is up", "Your server is back up."); echo "Email sent. "; endif; endif; function ping($host, $port, $timeout) { $tB = microtime(true); $fP = fSockOpen($host, $port, $errno, $errstr, $timeout); if (!$fP) { return "down"; } $tA = microtime(true); return round((($tA - $tB) * 1000), 0). " ms"; }.

There is no native ping function in PHP, so have a look at stackoverflow. Com/questions/1239068/… if you attempting to use this script... or of course use a monitoring system like nagios. Org – CodeReaper Sep 29 at 20:07 @CodeReaper The script already includes that ping function.

– Nick Sep 30 at 7:13 by bad, was surfing on my ipad and didn't think to try and scroll down. – CodeReaper Sep 30 at 8:33.

I personally use the Pingdom service if it can be pinged from the internet and is running an HTTP server on it. No need to really go deep into writing a special script.

Well as far as I know you can't create a cronjob with PHP , but what you can do is use crontab and this so you will be able to ping to required host also you can run instead exec("ping 1.2.3.4") in your script.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions