tags:

views:

327

answers:

3

Hello,

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 neccasary for paypal payments, so that does sound interesting.

I do a google "why use libcurl", but I haven't found an answer yet.

Could someone explain please?

thanks, Richard

+1  A: 

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.

mck89
thanks, I am reading up on itconnections are also faster then file or file_get_contentsI will definitivly start to use CURL then
Richard
+3  A: 

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.

JYelton
Also, when developing a recent PHP application, I was looking for a way to download data from multiple sources simultaneously. My original approach had been sequential, and took a very long time. Using curl I was able to set up an array of multiple connections, and execute them concurrently. Sort of like multi-threading.
JYelton
+1  A: 

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

Rick