So I want to execute a bash command from PHP on my web server. I can do this using shell_exec
. However, one of the commands I want to execute is curl
. I use it to send a .wav
file to another server and record its response. But when invoked from PHP, curl
doesn't work.
I reduced the error to the following small example. I have a script named php_script.php
which contains:
<?php
$ver=shell_exec("curl -F file=@uploads/2013-7-24-17-31-43-29097-flash.wav http://otherserver");
echo $ver
The curious thing is that when I run this php script from command line using php php_script.php
, the result I get is
Status: 500 Internal Server Error
Content-type: text/html
However, if I run curl -F file=@uploads/2013-7-24-17-31-43-29097-flash.wav http://otherserver
directly, I get the response I was expecting:
verdict = authentic
(Edit:) I should probably mention that if I put some bash code inside the shell_exec
argument which does not contain curl
, the bash command executes fine. For example, changing the line to $ver = shell_exec("echo hello > world");
puts the word "hello" into the file "world" (provided it exists and is writable). (End edit.)
Something is blocking the execution of curl when it is invoked from PHP. I thought this might be PHP's running in safe mode, but I found no indication of this in php.ini. (Is there a way to test this to make 100% sure?) What's blocking curl and, more importantly, how can I bypass or disable this block?
(And yes, I realize PHP has a curl library. However, I prefer to use commands I can run from the command line as well, for debugging purposes.)
cheers, Alan