php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74656 php -m command gives unreadable output when run via exec()
Submitted: 2017-05-26 09:52 UTC Modified: 2017-05-28 03:17 UTC
From: frederik at how2 dot be Assigned:
Status: Open Package: PHP options/info functions
PHP Version: 7.0.19 OS: CentOS 7.3
Private report: No CVE-ID: None
 [2017-05-26 09:52 UTC] frederik at how2 dot be
Description:
------------
When I run the command "php -m" using:
- the exec function
- the shell_exec function
- a perl equivalent of the above

The output is unreadable like this:
OUT:Array ( [1] => �EQ�n�0��W���CED�RUȱ7���.����á�G^{f|�޻�]rWO������)ؤB���Z���%�����y���8�5J�f�#�ҬC�dd�o�`28�ǯ���/$��RƁC�����ĪZ�iŞI���띯5-Y�d\Q( �t�ȏ�ݹ�a]M@�Z�m�{��\M=8�Q���5������V�� ) 
RET:0

Other command such as "php --version" and executing the same on PHP 5.6.30 work fine.
The get_loaded_extensions function also works fine.
also tried running it with --no-php-ini but got the same result.

I can reproduce this on 2 servers with PHP 7.0.19.

Test script:
---------------
exec($bin.' --version', $extout, $extret);
echo '<br />OUT:';
print_r($extout);
echo '<br />RET:';
print_r($extret);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-26 12:17 UTC] frederik at how2 dot be
Further investigation points to the php.ini option: zlib.output_compression = On
When we set it to Off, the output is OK.
 [2017-05-28 03:17 UTC] pollita@php.net
The only way this should be able to happen is if "HTTP_ACCEPT_ENCODING=gzip" is set in your process environment.  This can, in turn, happen if you're running your webserver PHP in CGI mode.  This isn't something which changed between PHP5 and PHP7, however.

Has anything else in your stack changed at the same time as upgrading?

For what it's worth, you can suppress the propagation of this environment variable to your child processes by adding the following to some earlier part of your application:
putenv("HTTP_ACCEPT_ENCODING=");
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 08 09:01:33 2024 UTC