Help needed in invoking shell command in PHP

Hi all..

can u please let me know how to use the unix shell curl command in PHP scripting,

sample of my code is given below,

<?php
$ch = shell_exec('curl  -H "Content-type: application/json" -H "Accept: application/json" --data-binary '{"text" : "how to check the temperature?"}' -H "X-JaskUid:111" -X POST "www.google.com/res"');
echo $ch;
?>

Output: Nothing happened.

Please help me in invoking a shell command using PHP. let me know whether any configuration needs to be done. I use in a wamp server for this.

Thanks in Advance

Why not use the builtin PHP curl support? See PHP: cURL - Manual. Is it not available to you?

I didn't go for php curl command, because the above said one line shell command have to be broken into much more lines to get executed. moreover i never used this before. If no help in the above problem i have to go for PHP curl only.

Thanks!

Yes, you have to write a few more lines of code but you really should be using libcurl via the built-in PHP curl support - not the curl utility.

1 Like

ok Thanks.. Am trying the PHP curl for this.. what is equivalent command in PHP curl for "--data-binary '{"text" : "how to check the temperature?"}'" and "-X POST "www.google.com/res""... i tried curl_setopt.. but the exact command i don't know. Can u please help out..

Here are the PHP cURL options.

Why not break your command line down into each flag/option and do the conversion step-by-step for the benefit of all?

1 Like