Best function used when grabbing body content

Which function is best to use in php when grabbing file content. I'm currently using fopen, but when I try to get the headers, it takes about 2-3 seconds to get the headers. Could HTTPRequest be the best option?

0


source to share


2 answers


Using cURL functions you can control timeouts etc. and they are pretty easy to use.



You can use curl_setopt($myCurlResource, CURLOPT_HEADER, true)

to include headers in the return value.

+2


source


I believe the best gain from overloading to speed with a function file_get_contents()

, it accepts a string as a URL or local path:

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

      



cURL is nice too, has a lot of additional options for sending things like POST variables and cookies, however it is not enabled by default with PHP, so you won't be able to use it in certain public hosting environments.

0


source







All Articles