So, I want to execute the 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 the .wav file to another server and record its response. But when called from the PHP curl does not work.
I reduced the error to the following small example. I have a script called php_script.php that contains:
<?php $ver=shell_exec("curl -F file=@uploads /2013-7-24-17-31-43-29097-flash.wav http://otherserver"); echo $ver
Curiously, when I run this php script from the command line using php php_script.php , the result 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 answer that I expected:
verdict = authentic
(Edit :) I should probably mention that if I put some bash code inside a shell_exec argument that does not contain curl , the bash command will execute normally. For example, changing the string to $ver = shell_exec("echo hello > world"); puts the word "hello" in the file "world" (provided that it exists and is writable). (Editing the end).
Something is blocking curl execution when it is called from PHP. I thought it could be PHP running in safe mode, but I did not find any signs of this in php.ini. (Is there a way to check this to make sure 100%?) What blocks curl and, more importantly, how can I bypass or disable this block?
(And yes, I understand that PHP has a curl library. However, I prefer to use commands that I can run from the command line for debugging purposes.)
amuses, Alan
source share