473,396 Members | 2,038 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,396 software developers and data experts.

fopen versus sockets & timeouts

ggg
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?

Jul 17 '05 #1
2 2189
<gg*@gg.com> wrote in message
news:MP************************@news.sf.sbcglobal. net...
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?


No. Check your stream timeout settings instead.
Jul 17 '05 #2
ggg
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?

No. Check your stream timeout settings instead.

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Heinz | last post by:
Hi All In a section of my code I open some other file via an URL to have that code executed like in $raw=fopen("http://webserver/some.php?aaa=$a&bbb=$b"); print "<td>$raw<td>"; This works...
4
by: Robert Schott | last post by:
Hi .. this is for sure the 1k question on fopen but maybe can someone tell me this weird staff if i'm writing: $H = fopen($value,"r"); while(!feof($H)) { $string = fgets($H,1024); .... .......
33
by: n00m | last post by:
import socket, thread host, port = '192.168.0.3', 1434 s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2.connect((host, 1433))...
12
by: Brett Robichaud | last post by:
I need to make access to a reference object threadsafe. My natural instinct was to simply use Monitor.Enter() and Exit(). The problem is that the object behind the reference changes frequently,...
5
by: Jae | last post by:
Real(const string &fileName) { FILE * myInputFile = fopen(fileName, "rt"); ..... fclose(myInputFile);
4
by: lucyachammond | last post by:
I have a 3rd party real-estate website written in php. I would like to call an asp script on a separate webserver each time a new real-estate item is added to the database on the php site. The...
6
by: Frieder Bürzele | last post by:
Hi, Im trying to integrate a rss feed into my page but struggle to fetch the dynamic generation of the rss feed If I type this into the browser as a result the xml file is shown as expected...
15
by: joker197cinque | last post by:
I'm trying to fopen a file this way: $handle = fopen("http://localhost/test.html", "r"); but tha page remains "loading .." for 30 seconds and then goes in timeout. However I can open that...
0
by: bramoin | last post by:
Hi, We are trying to decide if we should use Sockets or WCF for our project. We have two type of clients: 1. Users with IE accessing the server and so we know the answer there is WCF. 2. Processes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.