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.
source share