Forum Moderators: coopster

Message Too Old, No Replies

time out with $fopen?

time_out $fopen

         

john1000

10:53 pm on Nov 12, 2006 (gmt 0)

10+ Year Member



Hello,

The below code isnt full version but my question is this..
as it should grab an weather image from another site ,how can i built in a security (or IF statement) that when there's something wrong with the connection that it shows a standerd image..
Because if its waiting for the connectiuon and fails it messes up the place..
Any solution..?

if ( ($difference < $q) AND ($filesize!= 0) )
{ }
elseif ( ($difference > $q) OR ($filesize == 0) )

{
$fc = fopen("cache/latest_radar.png", "wb");
$file = fopen ("http://www.test.com/test.png", "rb");
if (!$file) {
$info = "E";
exit;
}
else
{
while (!feof ($file)) {
$line = fread ($file, 4096);
fwrite($fc,$line);
}
}
fclose($fc);
fclose($file);
$info = "F"; }

mcibor

11:03 pm on Nov 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Taken from
[pl2.php.net...]

If you need fopen() on a URL to timeout, you can do like:
<?php
$timeout = 3;
$old = ini_set('default_socket_timeout', $timeout);
$file = fopen('http://example.com', 'r');
ini_set('default_socket_timeout', $old);
stream_set_timeout($file, $timeout);
stream_set_blocking($file, 0);
//the rest is standard
?>

Hope this helps you

Regards
Michal

john1000

11:14 pm on Nov 12, 2006 (gmt 0)

10+ Year Member



thanks i saw that,but i also read somewhere that it doesnt work when in safe_mode.
Is that correct?

mcibor

1:14 pm on Nov 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, because:

When safe_mode is on, PHP checks to see if the owner of the current script matches the owner of the file to be operated on by a file function or its directory.

So the fopen will not work.

More here:
[pl2.php.net...]

Michal

john1000

1:21 pm on Nov 13, 2006 (gmt 0)

10+ Year Member



ah i see...
thanks..