2

I have a list of urls for some webpages and I want to make sure that this url ( webpage ) exists and not deleted or it doesn't exist. I want to do it in PHP.

How do I ping a webpage to make sure it's alive?

Mesaber
  • 57
  • 2
  • 6
  • Try this SO post, there is a nice example in it: http://stackoverflow.com/questions/1239068/ping-site-and-return-result-in-php – Bjoern May 22 '11 at 08:27
  • Do you want to do this on command or have it as a scheduled task? – alex May 22 '11 at 08:35

3 Answers3

3
$urls = array(...);

foreach($urls as $url) {
    $headers = get_headers($url);

    if ( ! $headers OR strpos($headers[0], '200 OK') === FALSE) {
       // Site is down.
    } 
}

Alternatively you could use ping.

$response = shell_exec('ping ' . escapeshellarg($url));

// Parse $response.

Update

You mention you want this to be scheduled. Have a look into cron jobs.

alex
  • 479,566
  • 201
  • 878
  • 984
1

Create a PHP script that fires off an HTTP Request to each URL that you want to be kept-alive.

PHP HTTP Request

I suggest setting up a Task in your operating system that accesses this script every 15 minutes in order to keep these applications alive. Here's some info on running PHP from the command line in Windows.

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
0

See http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=8&txtCodeId=1786 for a thorough implementation.

tofutim
  • 22,664
  • 20
  • 87
  • 148