I want to use shell_exec
to run curl
and get the response. The problem is that my shell exec command doesn't work when I run curl
, it works fine when I run curl
in cmd
or cygwin
. I'm using laravel 5.6 with php 7.2
I can run:
shell_exec("ping domain.com");
It return response like it has used to.
But I can't run:
shell_exec("curl some thing here");
It gives me null
when I use dd()
or blank when I print_r()
.
I know I can use guzzle, but I am just wondering why it doesn't work.
Consider using PHP Curl (IT's necessary to enable PHP curl extension). It's a safer way - You dont need to access shell + on many shared hostings, it's disabled - and also works natively under Windows.
The problem you are fighting off is caused probably by missing PATH. That's why it works in cygwin, not under native shell. Note that PHP execs in native shell.
curl需要完整 的路径,例如你的curl安装在F
shell_exec("F:\curl-7.74.0_2-win64-mingw\bin\curl http://fsdfd33333sfsdf.com/crontab/crontab/settingImgURL");