homepage Welcome to WebmasterWorld Guest from 54.204.58.87
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

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




msg:3932268
 5:42 pm on Jun 12, 2009 (gmt 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?

 

nick279




msg:3932270
 5:45 pm on Jun 12, 2009 (gmt 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

rocknbil




msg:3932281
 5:55 pm on Jun 12, 2009 (gmt 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.

Kavkan




msg:3932311
 6:50 pm on Jun 12, 2009 (gmt 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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved