dthh5038 2012-07-24 18:37
浏览 36

了shell_exec(); 在PHP中无法正常工作

I'm trying to execute a command thru shell_exec(); but it does nothing. I know shell_exec(); is enabled because these work perfectly:

echo shell_exec('which php');
echo shell_exec('ls');

They do output correctly.

The problem is when I want to execute something like this:

shell_exec("php file.php var1 var2 > /dev/null &");

It does nothing, but when I run it thru the Terminal on my computer, it does work. I have also tried doing it with the full path like this:

shell_exec("/usr/bin/php /full/path/file.php var1 var2 > /dev/null &");

And it doesn't work, but again... it works if I run it thru my Terminal's computer.

The php.ini safe mode is off, and there are no disabled functions on it, so I don't know what could be happening. And yes, I have access to SSH and got a dedicated IP.

  • 写回答

2条回答 默认 最新

  • doupingtang9627 2012-07-24 19:46
    关注

    Try to look at return code $return_var of the function (last arguments of functions system exec). It should be 0 if success. If it is 127 possibly command line is not permitted on the server or you don't have enough privilege to run commands from PHP scripts (it depends on the user/group from which scripts are executed). Otherwise function simply returns empty array of output, like nothing good or bad happened.

    I ran into similar situation not so long ago, ls was working Ok, while wget was always failing.

    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度