Quoting Arnout Boks <[EMAIL PROTECTED]>:
> Maybe it helps to open the address with the fopen( )- or file( )-function
> to read it's contents. I use this method to get data from (dynamic) html
> pages on another website. I don't have that much knowledge about Java
> servlets, so I don't know if this works for that also.

It should work for any HTTP URL. But I'd recommend using fsockopen()
instead of fopen(). fsockopen() has a built-in timeout, and you need
this if you don't want to make your visitors wait indefinitely. The
timeout works two-fold: there's a timeout for opening the socket,
specified in the fsockopen() call; then there's a timeout control set
with socket_set_timeout().

You can do something along these lines:
* open socket with fsockopen()
* if opening worked and it didn't time out, use socket_set_timeout()
* do a while loop based on feof() and socket_get_status() (check for
  end-of-file and read timeout, respectively)
* while in the loop, read from the socket

A common pitfall: you will also get the HTTP response headers this
way. Just skip everything at the top of the file until you meet a
double newline (\n\n) for the first time. But you may want to check
those headers to see if the server responded with a 200 OK code.
The code is the first word on the first line of the response.

Here's a nifty trick from the PHP-GTK crowd: use socket_set_blocking
to set the stream to NON-blocking mode. Then all read calls to the
socket will return immediately, regardless if they read something
or not. In the long run, this will give the same results as with
blocking mode, but you may save up a second or two due to increased
responsiveness. Oh, and very IMPORTANT, do a small usleep() in every
loop if you use non-blocking, even usleep(1000) will suffice;
otherwise you risk killing the CPU on the server.

-- 
Romanian Web Developers - http://ROWD.ORG

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to