如果我尝试在脚本中运行以下代码:
<?php exec("curl http://ww.google.com") ?>我得到了:
-bash-3.2$ php test.php
sh: /curl: No such file or directory使用shell_exec:
PHP Warning: shell_exec(): Cannot execute using backquotes in Safe Mode...如何将curl作为shell命令行运行?
这些错误发生在Linux上,在我的mac works上。
发布于 2011-09-28 02:04:26
问题是PHP安全模式是开启的,最好使用完整路径来运行cURL (感谢ghostJago和amosrivera)。使用以下命令运行脚本已修复此问题:
php -dsafe_mode=Off test.php我不想更改php.ini,但它也可以是一种解决方案。
shell_exec告诉你安全模式的问题,但exec只是告诉你一个错误的消息,希望我同时尝试了exec和shell_exec。
发布于 2011-09-27 23:57:50
在php.ini文件中禁用safe mode。还要检查是否安装了curl。
safe_mode = Off发布于 2018-07-30 18:54:23
要将bash命令(就像您可以从chrome-dev-tools复制)转换为php,请看一下下面的代码:https://incarnate.github.io/curl-to-php/
https://stackoverflow.com/questions/7572078
复制相似问题