Page 1 of 1

Retrieving a URL

Posted: Mon Jan 19, 2004 9:24 am
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

..

Posted: Mon Jan 19, 2004 9:50 am
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

Posted: Mon Jan 19, 2004 10:05 am
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:

Posted: Mon Jan 19, 2004 10:07 am
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