开发者

How can I run curl as shell command line in PHP

If I try to run this inside a script:

<?php exec("curl http://ww.google.com") ?>

I get:

-bash-3.2$ php t开发者_Python百科est.php 
sh: /curl: No such file or directory

using shell_exec:

PHP Warning:  shell_exec(): Cannot execute using backquotes in Safe Mode...

How can I run curl as shell command line?

Those errors are happening on Linux, on my mac works.


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

I do not want to change the php.ini but it could be a solution too.

shell_exec tells the safe mode problem, but exec just tell you an wrong message, hopefully I tried both exec and shell_exec.


Disable safe mode in your php.ini file. Also check if you do have curl installed.

safe_mode = Off


To convert from an bash command (like you can copy from chrome-dev-tools) to php take a look at this: https://incarnate.github.io/curl-to-php/


at the commandline, do this:

which curl

This will give you the absolute path to the curl program.

Then double check that safe_mode = Off is in your php.ini.

When you've done this, change your code to:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜