如何在PHP中将curl作为shell命令行运行

rta*_*oni 5 php curl

如果我尝试在脚本中运行它:

<?php exec("curl http://ww.google.com") ?>
Run Code Online (Sandbox Code Playgroud)

我明白了:

-bash-3.2$ php test.php 
sh: /curl: No such file or directory
Run Code Online (Sandbox Code Playgroud)

使用shell_exec:

PHP Warning:  shell_exec(): Cannot execute using backquotes in Safe Mode...
Run Code Online (Sandbox Code Playgroud)

如何将curl作为shell命令行运行?

这些错误发生在Linux上,在我的Mac上.

rta*_*oni 5

问题是PHP安全模式已启用,最好使用完整路径运行cURL(感谢ghostJago和amosrivera).使用以下命令运行脚本可修复此问题:

php -dsafe_mode=Off test.php
Run Code Online (Sandbox Code Playgroud)

我不想改变php.ini它,但它也可能是一个解决方案.

shell_exec告诉安全模式问题,但exec只是告诉你一个错误的消息,希望我尝试了两个execshell_exec.