I'm fetching a file from a remote website via the HTTP 1.0 protocol. I figured I'd be nice and use gzip when fetching the file as to minimize the bandwidth used.
No matter how I formed my headers I did not get gzipped content in the response although when testing it with a browser it did. I also get the gzip format served from my own website using my code.
I figured this was because their server is using chunked transfer encoding which is only available in HTTP 1.1.
I switched protocol to HTTP 1.1. This is my code below. My website answers to this, although it takes multiple seconds to do what 1.0 does instantly. When I try it on the remote website it keeps on loading forever without answering.
So my question is, why is 1.1 so slow?. Am I using a malformed header or something? Also, why does my page answer yet the other does not. Any input? Thanks.
$header = array(
'http' => array(
'method' => 'GET',
'header' => 'Accept-Encoding: gzip\r\n' .
'User-Agent: test\r\n)' .
'Accept-Charset: ISO-8859-1,utf-8\r\n' .
'Accept-Encoding: gzip, sdhc, deflate\r\n' .
'Host: www.mysite.test.com\r\n' .,
'protocol_version' => '1.1\r\n'
);
$context = stream_context_create($header);
$file_string = file_get_contents('www.mysite.test.com/test.txt', false, $context);
Edit: It definitely seems like its keeping the connection open until the servers keep-alive limit is reached. Took about 1.1 minute to get my answer from their webpage. Need to figure out how to close connection then. Otherwise it seems to work.