By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,824 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,824 IT Pros & Developers. It's quick & easy.

Setting a timeout when using fopen.

P: n/a
On my site I'm reading content from a URL with a statement like this:

if ($fp = @fopen("http://www.mydom.com/test.aspx", "r"))
{
do something
}
else
{
do something else
}

Which works absolutely fine if the remote site works, and fine if it's
totally unavailable... but sometimes the remote site allows the
connection, but takes EONS to server up any data. Which is totally
locking up my site.

How could I go about having some kind of timeout on the file open
operation?

TIA

Jan 29 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Aetherweb wrote:
On my site I'm reading content from a URL with a statement like this:

if ($fp = @fopen("http://www.mydom.com/test.aspx", "r"))
{
do something
}
else
{
do something else
}

Which works absolutely fine if the remote site works, and fine if it's
totally unavailable... but sometimes the remote site allows the
connection, but takes EONS to server up any data. Which is totally
locking up my site.

How could I go about having some kind of timeout on the file open
operation?
Hi,

fopen() can indeed handle URLs and return their content as it were a file
(using the fopenwrappers).

But if you need more control, you should use a socket.
Have a look at fsockopen:
http://nl2.php.net/manual/en/function.fsockopen.php

look at the last parameter (timeout).

Regards,
Erwin Moller

>
TIA
Jan 29 '07 #2

P: n/a
Erwin Moller wrote:
Aetherweb wrote:
>On my site I'm reading content from a URL with a statement like this:

if ($fp = @fopen("http://www.mydom.com/test.aspx", "r"))
{
do something
}
else
{
do something else
}

Which works absolutely fine if the remote site works, and fine if it's
totally unavailable... but sometimes the remote site allows the
connection, but takes EONS to server up any data. Which is totally
locking up my site.

How could I go about having some kind of timeout on the file open
operation?

Hi,

fopen() can indeed handle URLs and return their content as it were a file
(using the fopenwrappers).

But if you need more control, you should use a socket.
Have a look at fsockopen:
http://nl2.php.net/manual/en/function.fsockopen.php

look at the last parameter (timeout).
AHUM, scratch that last remark. ;-)

That timeout is only for the connectionprocess.
You need an extra function: stream_set_timeout() as described in the text.

Good luck.

Reagrds,
Erwin Moller
>
Regards,
Erwin Moller

>>
TIA
Jan 29 '07 #3

P: n/a
I really love these fancy acronyms like EONS. Perhaps the answer to original
question could be simple, but even after programming php for couple of
yaers, I have not yet hit my head to this acronym. Acronymfinders give me 7
different solutions, but none of them seems very right :-)

European Oncology Nursing Society
Early Onset Neonatal Sepsis
Elementary Objects of Neural Systems
Eastern Ontario Network Services
Enhanced Operator Name String
Executive Office of Neighborhood Services
Electronic Output Network System
Jan 29 '07 #4

P: n/a
Rik
P Pulkkinen <pe*************************@POISTATAMA.elisanet.f iwrote:
I really love these fancy acronyms like EONS. Perhaps the answer to
original
question could be simple, but even after programming php for couple of
yaers, I have not yet hit my head to this acronym. Acronymfinders give
me 7
different solutions, but none of them seems very right :-)
That's because it isn't an acronym. The OP made it somewhat harder on us
by using capitals, but an eon is just a geological time-period.
--
Rik Wasmus
Jan 29 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.