473,231 Members | 1,586 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,231 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 2183
<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: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.