-3

I hava a simple php script like this

<?php    
exec('foo you 2>&1', $output, $return_val);
print_r($output);

execute it on command line it gives out

Array
(
    [0] => sh: foo: command not found
)

but when I place it under a web server document directory and access it from browser it shows

Array ( )

I use nginx+phpfpm and server config is right.

As you see, I have redirect error from stderr to stdout. And more, the return_var is -1.

So the problem is that why it returns empty when accessed from browser while it is normal when executed on command line.

Thanks.

mononoke
  • 609
  • 6
  • 9
  • Possible duplicate of [php exec() is not executing the command](http://stackoverflow.com/questions/17914402/php-exec-is-not-executing-the-command) –  Dec 29 '16 at 07:22
  • Keep your language p.g –  Dec 29 '16 at 07:35

1 Answers1

0

I restart php-fpm and it works but I don't know why.

yxr ~ :( # ps aux|grep fpm
root        277  0.0  0.4 143416 10144 ?        Ss   Dec24   0:27 php-fpm: master process (/usr/local/etc/php-fpm.conf)
nobody    12971  0.0  0.9 2870504 19000 ?       S    Dec25   1:14 php-fpm: pool www
nobody    14133  0.0  1.0 2925356 21764 ?       S    Dec26   0:38 php-fpm: pool www
nobody    22487  0.0  1.0 2905708 22236 ?       S    Dec26   0:36 php-fpm: pool www
nobody    30670  0.0  0.9 2923280 19020 ?       S    Dec27   0:35 php-fpm: pool www
nobody    31239  0.0  0.9 2920428 19856 ?       S    Dec27   0:36 php-fpm: pool www
root      71753  0.0  0.1  12512  2340 pts/1    S+   10:49   0:00 grep --color=auto fpm
yxr ~ # pkill php-fpm
yxr ~ # php-fpm                                                                                                   
yxr ~ # ps aux|grep php-fpm
root      71764  0.0  0.4 143416  9920 ?        Ss   10:50   0:00 php-fpm: master process (/usr/local/etc/php-fpm.conf)
nobody    71765  0.0  0.4 143416  8380 ?        S    10:50   0:00 php-fpm: pool www
nobody    71766  0.0  0.5 143480 11256 ?        S    10:50   0:00 php-fpm: pool www
root      71776  0.0  0.1  12512  2312 pts/1    S+   10:51   0:00 grep --color=auto php-fpm
mononoke
  • 609
  • 6
  • 9