Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am attempting to connect to a server via PHP fsockopen to initially get a cookie for basic auth and then to persistently connect to a streaming server defined in the Location header of the response.

The problem is that my code freezes on fgets and never receives any response data from the destination server. I'm connecting via https on port 443 on an Amazon ec2 instance. The server connects fine via curl in my server's terminal or via my chome browser.

Is there an outbound firewall setting that I'm missing on ec2? I've even opened up the inbound 443 port on the server, but of course that seems pointless.

Any thoughts?

share|improve this question
I droped the amazon-ec2 tag because I'm pretty sure this is not related to that and it might scare some folks off. Can you confirm that you can use fsockopen() against some other https service on the web? – Caleb Apr 23 '11 at 8:13
I actually was testing against a different server with no problems. It turns out that it is a header required by the destination server, and had nothing to do with ec2. – elkelk Apr 23 '11 at 15:58
up vote 0 down vote accepted

I solved this problem by adding the header: "Connection: Close\r\n\r\n".

The initial request for the cookie returns a 302 redirect code and will sit on the open connection unless you pass that header.

Unfortunately, this little line had me stumped for a while.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.