Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use curl instead of other methods?

Tags:

php

libcurl

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?

like image 967
Richard Avatar asked Aug 28 '09 14:08

Richard


3 Answers

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().

like image 179
JYelton Avatar answered Oct 05 '22 22:10

JYelton


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

like image 27
Rick Avatar answered Oct 05 '22 22:10

Rick


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.

like image 45
mck89 Avatar answered Oct 05 '22 23:10

mck89