Slow HTTP / 1.1 response, remote file_get_contents server

I am retrieving a file from a remote website using HTTP 1.0. I thought that I would be nice and use gzip when you extracted the file to minimize the bandwidth used.

Regardless of how I formed my headers, I did not receive gzip content in the response, although when testing it with a browser this was done. I also get the gzip format, which is served from my own site using my code.

I realized that this is due to the fact that their server uses encoded transmission, which is available only in HTTP 1.1.

I switched the protocol to HTTP 1.1. This is my code below. My site responds to this, although it takes a few seconds to do what 1.0 does instantly. When I run it on a remote website, it constantly loads, not responding.

So my question is: why so slow? Am I using the wrong header or something like that? Also, why is my page responding and the other is 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 it keeps the connection open until the server support level is reached. It took about 1.1 minutes to get a response from his web page. Find out how to close the connection. Otherwise it will work.

+4
source share
1 answer

Well ... It seems like after a while the answer was obvious when I hit my head against the wall.

I moved Connection close to the top and it suddenly worked, but then the gzip setup stopped working. So I tried to understand why order seems to matter. It seems I quoted in single quotes instead of "causing \ r \ n to not evaluate correctly. At least I think this is a problem. Thanks, anyway ... I hate it when I make simple mistakes like this ...

Edit again: I still do not get gzips from the site, although it works from mine. I will try to copy the headers from the browser and see what happens.

Edit 2: There we go! It works as intended. Perhaps they are somehow filtering on user agents or something not.

Editing 3: Now I get really random results when downloading the same file several times. sometimes i get it gzipped, sometimes not. Their server randomly serves me as one of two headers. The only difference is Vary: Accept-Encoding and Content-Encoding: gzip. I thought that gzip will always be sent as soon as I say that I can handle this? My own server seems to be serving gzips all the time.

Edit 4: For some reason, I got gzip: ed sometimes and uncompressed sometimes when using an earlier version of MSIE 5.0 in the user agent. I could only understand the transfer of gzips to user agents capable of handling them, but at least it should be consistent. Anyway. Problem solved, thanks.

+1
source

All Articles