Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-19
3
Medium Priority
?
209 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

618 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