Retrieving a URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Retrieving a URL

Post by JayBird »

Hi,

Just a little problem i hope will be easy to solve.

One of our clients displays their share price on their websites homepage. This is supplied in an iFrame from another company (Hemscott).

What i want to be able to do is read the HTML from that URL, but if the task takes longer than say 3 seconds, display a message saying the share price is temporaritly unavailable.

Baiscally, is it possible to set a timeout on how long php will wait to retrieve a URL? if so, how?

Thanks

Mark
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

..

Post by ol4pr0 »

i am not clearly sure what you mean but,

i think what you are looking for can be found in youre php.ini
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

yep there is one option thro which u can limit the execution time of php script but i think it will effect ur every php file so its not a better approch :roll:
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

No, you've misunderstood.

The URL in the code below returns some HTML with the latest share price inlcuded.

Sometime, the server that gives this ffed is very busy and takes a long time to server the information. In such a case, i only want to wait say 3 seconds for the information to be supplied, otherwise, display a message saying the share prices are currently unavailable.

This is what i have come up with

Code: Select all

<?php
$url = "http://miranda.hemscott.com/servlet/HsPublic?context=ir&client=cah&path=trading&service=getDelayedPrices&symbol=CAH&market=NYSE&transform=dailyshareprice";
$fp = fopen($url, 80);
if (!$fp) {
   echo "Unable to open\n";
} else {
   stream_set_timeout($fp, 1);
   $res = fread($fp, 2000);
   echo "<pre>";
   var_dump(stream_get_meta_data($fp));
   echo "</pre>";
   fclose($fp);
   echo $res;
}
?>
Not sure how to test it as the url currently is working, but does the code look as if it would work?

Mark
Post Reply