I have PHP script with use of Zend_Http_Client.
Script do 2 things:
- "Expand" shortened urls + get mime-type of URL
- Get HTML content of text/html urls
I use this simple code:
$client = new Zend_Http_Client($url);
$response = $client->request('GET');
$headers = $response->getHeaders();
$body = $response->getBody();
All OK except situation when URL contains 100Mb MP3 file, for example. I need only HTML content, not MP3. So I want to config Zend_Http_Client to "don't download files more than 2Mb". Is it possible?
Yes, I can make 2 requests - first for get MIME of URL, and second to get HTML if MIME=text/html, but it is too expense to make 2 different requests.
So, question: how to check downloading content size and stop downloading without error when already downloaded content weight became more then 2Mb?