|
Posted by Gary L. Burnore on 08/31/07 16:15
On Fri, 31 Aug 2007 12:48:16 +0100, The Natural Philosopher <a@b.c>
wrote:
>Carl Vondrick wrote:
>> Albright.Brian@gmail.com wrote:
>>> I'm not even sure if PHP is the correct tool to do this for...but I'm
>>> wondering how difficult it would be to write something for my webpage
>>> that just tells if my file server is up or down (assuming either they
>>> are on the same network, or the server had a static IP).
>> Use PHP to ping it. If there's no response within 100ms, it's down. :)
>>
>> Carl
>OTOH a respsonse to ping doesn't mean its up, either..
Here's what we do to ensure a site is actually up:
Colons at beginning are to stop wordwrap, nothing more.
: <?php
: // create a new curl resource
: $ch = curl_init();
: ?>
: <H2>DataBasix OffSite Support</H2>
: <H4>Trying primary site...</H4>
: <?php
: // set URL and other appropriate options
: curl_setopt($ch, CURLOPT_URL, "https://server.domain.tld/sitealive.php"); # Locaton of sitealive.php
: curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
: curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
: curl_setopt($ch, CURLOPT_HEADER, 0);
: curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
: curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
: curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
: curl_setopt($ch, CURLOPT_MUTE, TRUE);
:
: if ( curl_exec($ch)) {
: // Site must be up
: // DO site is up stuff here if any
: } else {
: // Site is down. Darn...
: //
: echo "<H3> Primary site not available. </H3>";
: // This keeps it from paging more than once
: $checkfile = "./path/to/some/checkfile";
: if(file_exists($checkfile)) {
: echo "<H3>A message has already been sent to DataBasix Support.</H3>";
: } else {
: echo "<H3>Sending message to DataBasix Support...</H3>";
: $mailsubject = "Access problem=>Offsite to DataBasix Support";
: $mailto = "YOURPAGERGOESHERE";
: $mailmsg = "Userinfo: " . $_SERVER["REMOTE_ADDR"] . "\n";
: touch($checkfile);
:
: mail($mailto, $mailsubject, $mailmsg);
: }
: }
:
: // close curl resource, and free up system resources
: curl_close($ch);
: ?>
Sitealive.php goes on the server you want to monitor and contains only
the following:
: <?php
:
: echo "TRUE";
:
: ?>
--
gburnore at DataBasix dot Com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
Official .sig, Accept no substitutes. | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ 0 1 7 2 3 / Ý³Þ 3 7 4 9 3 0 Û³
Black Helicopter Repair Services, Ltd.| Official Proof of Purchase
===========================================================================
[Back to original message]
|