Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6565887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:09:01+00:00 2026-05-25T14:09:01+00:00

I have a server that I can use PHP on and a router that

  • 0

I have a server that I can use PHP on and a router that can be pinged from the Internet. I want to write a PHP script that sends a ping to the router every 5 minutes with the following results:

  • If the ping succeeds, then nothing would happen.
  • If the ping fails, then it waits a few minutes, and if it still fails it sends a warning to my e-mail address once.
  • After the router is pingable again it sends an e-mail that it’s OK.

Could this be done with PHP? How? Does anybody has a small PHP file that does this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:09:02+00:00Added an answer on May 25, 2026 at 2:09 pm

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

    <?php 
    
    //Config information
    $email = "your@emailaddress.com";
    $server = "google.com"; //the address to test, without the "http://"
    $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"; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script (running on a Linux server) that ouputs the names
I have a remote server that has win2003 installed I can connect to the
Is there a way that I can have a server control MyControl<T> so that
I have a server application that, in rare occasions, can allocate large chunks of
I have a VARCHAR column in a SQL Server 2000 database that can contain
I already have a deploy.rb that can deploy my app on my production server.
I have a table which contains my ads that can be searched in sql-server-2008.
Can I setup Team Foundation Server in such a manner that every uer have
I have a server that sends data via a socket, the data is a
I have a Web server that updates its data once per minute, and want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.