我如何在PHP中运行curl作为shell命令行
如果我尝试在脚本中运行此脚本:
If I try to run this inside a script:
<?php exec("curl http://ww.google.com") ?>
我得到:
-bash-3.2$ php test.php
sh: /curl: No such file or directory
使用shell_exec:
using shell_exec:
PHP Warning: shell_exec(): Cannot execute using backquotes in Safe Mode...
如何以shell命令行运行curl?
How can I run curl as shell command line?
这些错误发生在Linux上的我的mac工作。
Those errors are happening on Linux, on my mac works.
问题是 PHP
安全模式,最好使用完整路径运行 cURL
(感谢ghostJago和amosrivera)。使用以下命令运行脚本解决了问题:
The issue is that PHP
safe mode is on and it is better to use the full path to run cURL
(thanks ghostJago and amosrivera). Running the script with the following command fixed the issue:
php -dsafe_mode=Off test.php
我不想更改 php.ini
,但它可以是解决方案。
I do not want to change the php.ini
but it could be a solution too.
shell_exec
告诉安全模式问题,但 exec
只是告诉你一个错误的消息,希望我试过 exec
和 shell_exec
。
shell_exec
tells the safe mode problem, but exec
just tell you an wrong message, hopefully I tried both exec
and shell_exec
.