Connecting Tech Pros Worldwide Help | Site Map

fopen versus sockets & timeouts

ggg@gg.com
Guest
 
Posts: n/a
#1: Jul 17 '05
Here's what I'm trying to do. The server serves up XML documents based
on what I specify in the GET string. This is on a server I have no
control over.

There is a lag between the time when I issue the GET request, and when
I actually get the response. (I suspect because the server has to dig
for the data and format it. In any case, it's longer than say, a simple
HTML page request to the web server.)

When I manually cut and paste the GET url into a browser, it sometimes
takes up to 20 seconds to get the response back (the popup tell me to
save the file).

When I fopen() it, sometimes it works, sometimes it doesn't. I tried
using set_time_limit(0), but that doesn't affect it.

I believe I might have to do a socket call in order to have more fine
tune control over the HTTP request.

Am I heading down the right path?



Chung Leong
Guest
 
Posts: n/a
#2: Jul 17 '05

re: fopen versus sockets & timeouts


<ggg@gg.com> wrote in message
news:MPG.1c72d78394b04c8d989687@news.sf.sbcglobal. net...[color=blue]
> Here's what I'm trying to do. The server serves up XML documents based
> on what I specify in the GET string. This is on a server I have no
> control over.
>
> There is a lag between the time when I issue the GET request, and when
> I actually get the response. (I suspect because the server has to dig
> for the data and format it. In any case, it's longer than say, a simple
> HTML page request to the web server.)
>
> When I manually cut and paste the GET url into a browser, it sometimes
> takes up to 20 seconds to get the response back (the popup tell me to
> save the file).
>
> When I fopen() it, sometimes it works, sometimes it doesn't. I tried
> using set_time_limit(0), but that doesn't affect it.
>
> I believe I might have to do a socket call in order to have more fine
> tune control over the HTTP request.
>
> Am I heading down the right path?[/color]

No. Check your stream timeout settings instead.


ggg@gg.com
Guest
 
Posts: n/a
#3: Jul 17 '05

re: fopen versus sockets & timeouts


Hi,

Thanks for the suggestion - I tried setting the socket timeout with
stream_set_timeout() and it seems to have fixed the problem:

function get_fopen_contents($url)
{
if (!$handle = fopen("$url", "r")) return -1;
stream_set_timeout($handle, 1000);
while (!feof($handle))
{
$contents .= fread($handle, 8192);
}

if (fwrite($handle, $contents) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
fclose($handle);

return $contents;
}

However, I didn't realize there already was a file_get_contents() so I'm
using that.

Now, I guess by using file_get_contents() I have no control over the
timeout, because I need to refer to the handle of the stream in some
way. Right?
[color=blue]
>
> No. Check your stream timeout settings instead.
>
>
>[/color]
Closed Thread