Why is file_get_contents() faster than using fsock_open()?

Posted by eds on Stack Overflow See other posts from Stack Overflow or by eds
Published on 2010-12-22T01:41:13Z Indexed on 2010/12/22 1:54 UTC
Read the original article Hit count: 534

Filed under:
|

In PHP, sometimes I want to send an HTTP request to a remote site just to look at the response headers, so I declare it all manually and use the fsock_open() function. However, this goes much slower than calling file_get_contents() with a remote URL (which loads the whole page content). Why is this? Is there a good alternative way to get just the response headers (to check if a page returns a 404 error, for example) that works as fast as file_get_contents()?

© Stack Overflow or respective owner

Related posts about php

Related posts about http-headers