Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Is curl something that's not expected to be installed on servers? I'm working for a small development shop and 99% of the problems that I'm having is regarding curl. Most of the projects that I'm working on involves calling a web API. Most web API's suggests using curl by default since you have to pass in a POST data in the request. Every time I complain to my senior that the server that I'm working on doesn't have curl installed the excuse that I'm always getting is that curl is not needed you can always use file_get_contents.

So the question: is curl something that's not expected to be installed on servers that runs PHP, should I always develop using file_get_contents and not curl? Are there any advantages of using file_get_contents over curl or vise versa?

If it helps, the context here is wordpress plugins, shopify apps, drupal modules and other bits of code that a lot of people can install.

share|improve this question
1  
Are you talking about the curl command-line tool? Or the libcurl library? –  Carson63000 Nov 11 '13 at 6:43

2 Answers 2

up vote 2 down vote accepted

The only way to be sure is to test features that you need. For example, in php, you can use Zend Framework's http client which comes with a socket adapter and a curl adapter. The you can test if curl module was available, if not then just use the socket adapter.

Using file_get_contents() for Api calls is not very convenient if you want to check status code and http headers and there's a whole lot more options you can set with curl.

share|improve this answer

The Requests library may be a good solution to your problem: http://requests.ryanmccue.info/

This library will take care of falling back to another request method such as file_get_contents() if libcurl is not installed on the server.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.