tags:

views:

22

answers:

2

To get the contents of a web page which is better: 1) To use Curl 2) file_get_contents 3)Any thing better than the above two.

Thanks for answers in advance

A: 

1) cURL gives you much much more advanced features about sending cookies, headers, time-to-try, etc and is widely supported on webhosts.

2) On the other hand, file_get_contents is better for quick-jobs (and beginners) when you do not need anything fancy and you are totally sure that it is enabled on the server. Most of the times, it is disabled.

3) There is nothing better than cURL.

shamittomar
Most of the hosts I've seen have the http stream wrapper enabled. (And I wouldn't say there's nothing better than cURL.)
zneak
@zneak, yes but most cheap and free webhost that usually oversell have this disabled. In any case, I would stick to cURL. If I need simplicity, I just make a function curl_file_get_contents() myself that takes just the URL and returns the results.
shamittomar
+1  A: 

It all boils down to your needs. file_get_contents is a simple and convenient way to get the contents of a webpage, if the HTTP headers it sends are okay for you. However, if you need more complexity, like HTTP authentication or custom headers, cURL will be a better fit.

If you just want to retrieve the contents of a public URL, I'd go for file_get_contents.

zneak