Welcome to WebmasterWorld Guest from 54.211.180.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)

New User

10+ Year Member

joined:May 12, 2006
posts: 21
votes: 0


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 June 12, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:July 21, 2008
posts:103
votes: 0


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 June 12, 2009 (gmt 0)

Senior Member

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

joined:Nov 28, 2004
posts:7999
votes: 0


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 June 12, 2009 (gmt 0)

New User

10+ Year Member

joined:May 12, 2006
posts:21
votes: 0


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?

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members