繁体   English   中英

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

[英]How can I run curl as shell command line in PHP

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

<?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上。

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

php -dsafe_mode=Off test.php

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

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

禁用php.ini文件中的safe mode 还要检查是否安装了卷曲。

safe_mode = Off

要从bash命令(就像你可以从chrome-dev-tools复制)转换到php,请看看这个: https//incarnate.github.io/curl-to-php/

在命令行,执行此操作:

which curl

这将为您提供curl程序的绝对路径。

然后仔细检查你的php.ini中是否有safe_mode = Off

完成后,将代码更改为:

<?php exec("path/you/got/from/which/curl http://www.google.com") ?>  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM