?
Solved

Check if a remote www-page is online...

Posted on 2006-11-19
3
Medium Priority
?
206 Views
Last Modified: 2007-01-05
Hi,

I have a PHP-page that fetches information from another site, BUT the problem is that the site sometimes is not available or extremely slow. Hence, I would like to check if the site is online, prior to fetching the information from the site. How do I do that in the best way?

I have tried to use both
fsockopen("www.example.com",80);
and
file_get_contents()

Is there someway to set a timeout-limit?

Thanks in advance,
Jan
0
Comment
Question by:madwax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Accepted Solution

by:
rhickmott earned 1200 total points
ID: 17976721
You shoul be able to do this in the fsock declaration.

fsockopen ( string target [, int port [, int &errno [, string &errstr [, float timeout]]]] )

Basically declare

fsockopen("www.example.com",80,$errno, $errstr,5)

will time out after 5 seconds and you can use the $errno and $errstr values to ask why. You can then do

if (!fsockopen("www.example.com",80,$errno, $errstr,5)) {
      echo("Site is dead");
} else {
     echo("Alive");
}

If you want to set a limit on how long your script spends reading data then you can use

http://us2.php.net/manual/en/function.stream-set-timeout.php

This function shoulw allow you to set a timelimit on streams
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question