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

PHP Server Side Scripting Forum

    
check a website if up in php
get the header of a page through php to check
copongcopong




msg:1245301
 5:49 am on Dec 21, 2003 (gmt 0)

is there a feature in php that would lt you get the header part of a site to check if it is up (for faster execution)? I use fopen("www.url.com", "r") but it take sometime to execute the script since I am doing a loop for 5 sites.

any possible (faster) idea would be greatly appreciated. Thanks.

 

NickCoons




msg:1245302
 6:55 am on Dec 21, 2003 (gmt 0)

Even requesting the header information only probably won't make much of a performance difference, because once the server responds it generally spews the HTML output pretty quickly. If you're making one request at a time, then you're going to have to wait for each to respond, or timeout, before moving on to the next.

However, you could have two seperate scripts. One (the slave) that makes the request and writes its findings to a file, and another (the master) that calls the first once for each site. This way the master script can run the slave script repeatedly, so you'll have multiple instances of the second script running at once all checking multiple web servers to see if their up. Once completed, the master script will check the file for the findings and report back to you.

jamesa




msg:1245303
 1:07 pm on Dec 21, 2003 (gmt 0)

How is this (spawning children) done in PHP, btw? Anyone know?

NickCoons




msg:1245304
 8:34 pm on Dec 21, 2003 (gmt 0)

I've never tried it myself, but I would imagine using exec() along with the & symbol at the end of your command-line would do it. Using the & symbol at the end of the command-line in Linux makes the command execute in the background and return control immediately. It may return control in a similar fashion when run using exec().

daisho




msg:1245305
 2:21 pm on Dec 22, 2003 (gmt 0)

Curl is the answer. I use it all the time.

As was mensioned before your speedup would not be that much faster but you can either use the "HEAD" request in replace of the "GET" request or you could use "ETag" or "If-Modified-Since".

Just make sure you are requesting an HTML page. If you are requesting a dynamic page then all these methods will not work out of the box since your webserver will not know how to answer them and the logic must be built into the script.

I think your easiest is the "HEAD" request option. But really for your purposes just simply create an HTML page that simply contains "OK" and use your fopen method. An extra 2 bytes of data will not hit your time at all. Then you can simple see if you got "OK" returned.

daisho.

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