-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.

2
  • Possible duplicate of php exec() is not executing the command Commented Dec 29, 2016 at 7:22
  • Keep your language p.g Commented Dec 29, 2016 at 7:35

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.