1

Although i don't think it's possible but is it a way to get a page size without downloading it?(it's seems silly but anyway i wanna ask it here)

you can curl a page and get it's size but i don't want to dl the page and also there is nothing interesting in the header with text/html.

2
  • Truly speaking you can't. Because you have no idea what the page's size is, unless you load it. Think of images, scripts, styles embedded on the page.
    – Prasanth
    Sep 30, 2012 at 19:24
  • 1
    curl reads text and all it see is text if u wanna do that u should go into all links and resources one by one find out what is there size
    – pouya
    Sep 30, 2012 at 19:30

3 Answers 3

4

Query the Content-Length property from the page header.

As defined by Section 14.13 of the Hypertext Transfer Protocol Documentation.

3
  • 1
    Well I stand corrected. Check my comment on the question. I now see that curl too downloads just the page of size specified by Content-Length. It doesn't load the images, scripts, styles etc. right? If so, yeah Content-Length should be it.
    – Prasanth
    Sep 30, 2012 at 19:26
  • it works for other mime/types except text/html cause info is in the header
    – pouya
    Sep 30, 2012 at 19:35
  • @goldenparrot how u get the text size of the page all i get is -1
    – pouya
    Sep 30, 2012 at 19:36
3

Use the HEAD HTTP method instead of GET:

The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself.

2
  • it's better to use get_headers() php function instead of curl because it's so much faster. anyway i can't see content-lengeth using head method for text/html mime type
    – pouya
    Sep 30, 2012 at 20:36
  • i used curl with curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD') also neither way works
    – pouya
    Sep 30, 2012 at 20:38
0

Even making a HEAD request doesn't guaranty u will get content-length in the output. check it for yourself:

stream_context_set_default(
    array(
        'http' => array(
            'method' => 'HEAD'
        )
    )
);

var_dump(get_headers("http://www.stackoverflow.com", 1));
var_dump(get_headers("http://www.google.com", 1));
var_dump(get_headers("http://php.net/", 1));

I think the best option is still to go and dl the page using curl and then see what's the size(pure text) of the page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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