Welcome to WebmasterWorld Guest from 184.73.126.70

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP script to find out if a url is active and running

   
5:42 pm on Jun 12, 2009 (gmt 0)

5+ Year Member



Hi all, I'm currently trying to devise a script to send out a notification email if a particular URL is not working.. for example, if the server is down, or if for some reason the URL returns an error or some.

Any suggestions as to how I can tell if a particular URL is not functioning at a particular time?

5:45 pm on Jun 12, 2009 (gmt 0)

5+ Year Member



Not working?

Does this mean the page throws an error (404) or another kind of error?

There are several reasons a page could fail:-

- server offline
- database offline
- programming error

to name a few

Another method is to setup apache/your webserver to email a 404 (or 501 etc) to you

5:55 pm on Jun 12, 2009 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I'm currently trying to devise a script to send out a notification email if a particular URL is not working.... if the server is down, or if for some reason the URL returns an error or some.

Use curl in a cron job.

Logic is

$result = curl url

if (preg_match('/error/im',$result) or preg_match('/not found/im',$result)) { send_error_mail($result); }

In send_error_mail you'd add all environment and input variables as well as the curl'ed result, get as much info as you can.

Another is to use curl just to get at the headers, see the php.net documentation on using curl.

6:50 pm on Jun 12, 2009 (gmt 0)

5+ Year Member



Nick, yes by 'not working' I meant any sort of error. The issue is that there are multiple people submitting code udpates and some of these updates cause errors. Hence I'm trying to send out an email as soon as such a scenario occurs.

Thanks rockenbil, I'll look into that.

Also, would anyone know of any existing application with similar funcationality that I could lookover?

 

Featured Threads

Hot Threads This Week

Hot Threads This Month