473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Setting a timeout when using fopen.

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
4 7621
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Stuart Norris | last post by:
Dear Group, I am having a problem setting SocketOptionName.SendTimeout on a client TCPIP application using the sockets in .NET. From the on-line help it is possible to set a...
1
by: ArunPrakash | last post by:
Hi, I want to implement a method which will poll database for messages. But i want to provide a method that will specify a timeout until which it will be polled and after that it will throw an...
11
by: Frank Rizzo | last post by:
Hello, My c# based windows service takes a while to dispose. I have to release bunch of resources all over the place and unfortunately it can take 20-40 seconds before I can cleanly exit. ...
1
by: Scott Walters | last post by:
Hi, I have an asp.net webapp that uses some javascript in a hidden frame on the browser to poll the server every 30 seconds, using an http post. I also want my sessions to timeout in the...
2
by: hakim | last post by:
Hi NG, I have my own apache server 2.0.54 running with php 4.3.10. I got a little logical problem here about http requests. I have written a small php script which waits for x seconds. Every...
4
by: UJ | last post by:
I have a page where the user can upload a video file. As you can guess, this may take a while. Is there a way I can change the session timeout for just this one page? I would also want to change...
0
by: Jonathan Wood | last post by:
I seem to be having errors creating and accessing an SQL database. Unfortunatley, I am brand new to SQL setup and administration issues so this really is not my area of expertise. I know I had...
1
by: a.r.austin | last post by:
Hello, I am trying to download a few files one after another from a remote server. Problem is that I don't know how to, or if I am able at all, set a time out for download. I don't want to time...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.