It's not possible to get the command line equivalent (options) to execute the tool curl
from the PHP library cURL
.
Both tool and PHP library use libcurl
to perform client-side URL transfers, which is a C library. But that's all. Very likely you have a PHP equivalent for most of curl
options available in cURL
, however, it's not a rule.
I don't think you simply would like to do requests from your application using curl
, if you want so, you'd be using PHP library's. That said, there is no easy way to get what you want. Probably you'll need to build the command as a string. Something like this:
function getCurlCommand($url, $method = 'GET', array $params = null /* , ... */ )
{
$cmd = 'curl';
$params = [];
if ($method !== 'GET') {
$params[] = '-X ' . $method;
}
if ($data !== null) {
$params[] = '-d ' . http_build_query($data);
}
// ...
return $cmd . ' ' . implode(' ', $params) . ' ' . $url;
}