speeding up socket connections

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

i'm trying to write a php script that sends an http request to a
server, get some info. from that server, and print it to the screen.
unfortunately, this script takes longer to connect than i'd like.
replacing the server's ip address with noticeably speeds
things up, but doesn't work if someone's on a virtual host (the paths
would be different).

here's the script i'm using:

  $fsock = fsockopen('tcp://ipaddress',80,$errno,$errstr,1);
  fputs($fsock,"GET /filename.txt HTTP/1.0\r\n");
  fputs($fsock,"Host: domain.com\r\n\r\n");
  while (!feof($fsock))
    echo fgets($fsock);

i'm aware that fopen would work in this particular case, but in the
context of what i'm trying to do, it doesn't (i don't, ultimately, want
to get the contents - i just want to send an http request and be done
with it, for the purposes of initiating time consuming tasks such as
backups in safe mode, without requiring the user wait for the task to

any ideas as to how i could speed the above code up?

alternatively, any ideas how, when ipaddress is replaced with, the path on the domain that's being requested could be
adjusted to the real host (as opposed to the virtual one)?

Re: speeding up socket connections

Quoted text here. Click to load it

Just because your fopen() a URL doesn't mean you have to get the contents.
Hint: don't call fread().

Site Timeline