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
Retrieving a URL
Moderator: General Moderators
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
Not sure how to test it as the url currently is working, but does the code look as if it would work?
Mark
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;
}
?>Mark