tags:

views:

66

answers:

2

What is the best function to use in php when grabbing the contents of a file. Currently Im using fopen but when I try to get the headers it uses roughly 2-3 seconds to get the headers. Would HTTPRequest be a better option?

+2  A: 

Using the cURL functions gives you control over timeouts etc, and they're pretty simple to use.

You can use curl_setopt($myCurlResource, CURLOPT_HEADER, true) to include the headers in the return value.

Greg
A: 

I believe the best overhead-to-speed payoff is with the file_get_contents() function, it accepts a string as a URL or local path:

<?php
$body=file_get_contents('http://google.com');
?>

cURL is good too, has many more options for sending things like POST variables and cookies, however it does not come enabled with PHP by default, therefore you may not be able to use it in certain shared hosting environments.