How to convert Php CURL request to command line curl How to convert Php CURL request to command line curl curl curl

How to convert Php CURL request to command line curl


take a look at https://github.com/biganfa/php2curl. Start a webserver, send your request, and you will get the command line cURL version of the request using the library.


Please note that this is a workaround only.

Try to assemble your http request in Postman which is a really rich tool for testing APIs. It is a Chrome plugin, and available from the Chrome webstore for free (link). Alternatively, you can install it as a standalone client too from their website.

It has a nice feature which let you to grab the curl command wrapped in different languages/formats of your preference. In your case, in BASH too.

Put the request together then:

  • click "Code" (Right under the "Save" button)
  • choose "cURL" from the dropdown list
  • click "copy to Clipboard"

...and that's it, you have your preformatted cURL command line.

Also, there's a tool called cURL-to-PHP written in JavaScript, which does the exact thing you'd like to do.

If you take some time, you can translate the converter logic to PHP with little effort (eg. you don't need to research every aspects of cURL internals).