Question

I would like to know why it is better to use curl instead off other methods like $ret=file($url) in php. This is actually used to access an http api for an sms gateway.

Someone dropped a "I would recommend using curl for http connections", but I don't know why.

I just read that it is necessary for Paypal payments, so that does sound interesting.

I did a Google search "why use libcurl", but I haven't found an answer yet.

Could someone explain please?

Was it helpful?

Solution

I think the FAQ on the curl site says it best:

1.2 What is libcurl?

libcurl is a reliable and portable library which provides you with an easy interface to a range of common Internet protocols.

You can use libcurl for free in your application, be it open source, commercial or closed-source.

libcurl is most probably the most portable, most powerful and most often used C-based multi-platform file transfer library on this planet - be it open source or commercial.

Also, curl facilitates downloading data from multiple sources simultaneously with better efficiency than say file_get_contents() or file().

OTHER TIPS

Well, I don't know much about other methods of doing HTTP calls in PHP, so I'm not sure if they can do this or not, but Curl can mimic a web browser in pretty much every way, by setting headers, even the user-agent header, etc so that the web server just thinks its a browser which can be important as some sites will try to stop access from anything that isn't a traditional browser

Curl extension has a lot of options that you can set, for example the connection time out. You can also add post variables or access the site with a specific referer. I also reccomend you to use CURL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top