我如何在PHP中运行curl作为shell命令行 [英] How can I run curl as shell command line in PHP

查看:1252
本文介绍了我如何在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.

这篇关于我如何在PHP中运行curl作为shell命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆