zliboutputcompression
Read or set PHP
zlib.output_compressionacross all php.ini files
- Command:
/go/zliboutputcompression - Category: PHP
- Required arguments: None. With no argument it sets the value to
On. - Optional argument:
[value]orreturn - Output: A confirmation line, or the current value with
return - Last updated: 2026-11-19
On this page: Overview · Quick start · Syntax · Arguments · Output · Examples · Troubleshooting · Details · See also
Overview
/go/zliboutputcompression changes the PHP setting zlib.output_compression in every php.ini file on the server. When the setting is on, PHP compresses the pages it produces (with gzip or deflate) for browsers that accept compressed content. This makes pages smaller and faster to download. It:
- finds every
php.inifor every installed PHP version (web, command line, and Apache) - sets
zlib.output_compressionto the value you give, orOnif you give none - schedules a reload of PHP-FPM about one minute later so the change takes effect
The setting works together with compression done by the web server. See gzip. If both are on, the responses are compressed in PHP, and the web server normally leaves them alone, so it is enough to use one of the two.
The value can be On, Off, or a whole number, which is the size of the compression buffer in bytes. PHP's default is Off.
PHP lets a site override this setting in its own .user.ini file or with ini_set(), so the value you set here is a server-wide default.
[!WARNING] The change applies to every domain. Compression can interfere with scripts that stream their output or send their own
Content-Lengthheader, such as large downloads, progress pages, and server-sent events. Test a site before turning it on for everything.
Quick start
# Check the current value
/go/zliboutputcompression return
# Turn it on
/go/zliboutputcompression On
# Turn it off
/go/zliboutputcompression Off
Syntax
/go/zliboutputcompression [value]
/go/zliboutputcompression return
| Form | Behavior |
|---|---|
/go/zliboutputcompression |
Sets zlib.output_compression = On in every php.ini. |
/go/zliboutputcompression <value> |
Sets zlib.output_compression = <value> in every php.ini. |
/go/zliboutputcompression return |
Prints the value from the first php.ini found, then exits with code 1. |
The command does not toggle the setting. Running it with no argument always sets On.
Arguments
| Argument | Required | Default | Notes |
|---|---|---|---|
[value] |
No | On |
Use On, Off, or a whole number. The value is not validated, and if you pass several words they are joined with spaces. |
return |
No | — | Prints the current value. Not case-sensitive. |
The command has no other options.
Files changed
Only files that exist are changed.
| System | Files |
|---|---|
| AlmaLinux, Rocky, CentOS, Red Hat, Fedora | /etc/php.ini and /etc/opt/remi/<version>/php.ini for each installed version |
| Debian, Ubuntu | /etc/php.ini and, for each installed version, /etc/php/<version>/fpm/php.ini, /etc/php/<version>/cli/php.ini, and /etc/php/<version>/apache2/php.ini |
Output
| Outcome | What you get |
|---|---|
return |
The current value, such as Off, from the first file found. Empty if that file has no zlib.output_compression line. Exit code 1. |
| Value set | Zlib Output Compression updated successfully. |
| Unsupported operating system | Unknown operating system. |
The confirmation line is printed even if no php.ini was found or changed. The command doesn't list the files it edited.
Logging
Every run is appended to /var/log/go/zliboutputcompression.log.
Examples
# Read the current value
/go/zliboutputcompression return
# Turn compression on for the whole server
/go/zliboutputcompression On
# Turn it off again
/go/zliboutputcompression Off
# Check the result on a Debian or Ubuntu server
grep -H '^zlib.output_compression' /etc/php/*/fpm/php.ini
# Check the result on an AlmaLinux, Rocky, or CentOS server
grep -H '^zlib.output_compression' /etc/opt/remi/*/php.ini
# Check that a page is compressed
curl -s -H "Accept-Encoding: gzip" -D - -o /dev/null https://example.com/ | grep -i content-encoding
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The change doesn't apply right away | The reload is scheduled for about a minute later with at. |
Wait, or run fpm with reload. Check that the atd service is running. |
| Sites using Apache's PHP module don't change | Only a PHP-FPM reload is scheduled. | Reload the web server with web. |
| One site isn't affected | The site sets its own value in .user.ini or with ini_set(). |
Change the site's own setting. |
| Pages aren't compressed although the setting is on | The browser didn't ask for compressed content, or the web server or a proxy removes it. | Test with the curl command above. |
| Downloads or live progress output break after turning it on | Compression interferes with scripts that stream or set Content-Length. |
Turn it off, and compress at the web server with gzip instead. |
return shows a small number such as 6 instead of On or Off |
The first match was zlib.output_compression_level, which was set before the real line. |
Read the file by hand. See Notes for maintainers. |
return prints an empty line |
The first php.ini found has no zlib.output_compression line, so PHP uses its default (Off). |
Set the value, or check the file by hand. |
Zlib Output Compression updated successfully. but nothing changed |
No php.ini file was found. |
Check that PHP is installed. See Files changed. |
Permission denied when adding the line |
The command wasn't run as root. |
Run it as root. |
An odd value, such as On please, was written |
Several arguments were passed and joined together. | Pass exactly one value. |
The command failed with a value that contains / or & |
The value is inserted into a sed command. |
Use only On, Off, or a number. |
Exit code 1 after return |
By design. | Ignore it for return. |
Details
What it does
- Logs the call to
/var/log/go/zliboutputcompression.logand reads the operating system name from/usr/local/goadmio/linux/os.db. - Builds the list of
php.inifiles for the operating system. Stops withUnknown operating system.for any other system. - For each file that exists:
- reads the first line that starts with
zlib.output_compressionand takes its value - for
return, prints that value and stops - with no argument uses
On, otherwise uses all arguments as the value - replaces every
zlib.output_compressionline withzlib.output_compression = <value>, or adds the line at the end if the file has none
- reads the first line that starts with
- Prints
Zlib Output Compression updated successfully. - If no pending
atjob already containsfpm reload, schedules/go/fpm reloadone minute later.
Reload
Because of step 5, several runs within a minute cause only one reload. Command-line PHP picks up the change the next time it starts. PHP-FPM picks it up at the reload.
Notes for maintainers
This command has the same code as fileuploads. The problems listed there apply here too, in particular the missing value check, the reload check, and the missing root check. The points below are specific to this setting.
| Issue | Why it matters | Suggested fix |
|---|---|---|
With no argument it sets On, but the index calls it "Read or set" |
The no-argument behavior isn't documented elsewhere. | Say in the description that it turns the setting on. |
return reads only the first existing file and exits with 1 |
Misses other files that differ, and success looks like failure. | Print every file with its value, and exit 0. |
| The value is not validated | Any text is written to php.ini, and a value with / or & breaks the sed command or can inject sed commands. The setting accepts On, Off, or a number. |
Accept only those values, and quote them. |
The read pattern ^zlib.output_compression*=* is loose |
It also matches zlib.output_compression_level, so return can show the level. The dots match any character. |
Use ^[[:space:]]*zlib\.output_compression[[:space:]]*= in both places. |
| Inline comments end up in the value | A line such as zlib.output_compression = On ; comment returns On comment. |
Cut the value at the first ;. |
echo ... >> $File and grep -q run without sudo |
Appending fails when the command isn't started as root. | Re-run through sudo at the top, like most other commands. |
sed replaces every matching line |
Duplicate directives are all rewritten. | Replace only the first match. |
| The success message always prints | A run that changed nothing still reports success. | Count the files changed, and print them. |
| No backup and no syntax check before editing | A bad value can leave PHP unable to start. | Keep a backup, and test the file before the reload. |
Only fpm reload is scheduled |
Apache's PHP module (apache2/php.ini) is changed but not reloaded. |
Also reload the web server when Apache's module is in use. |
The Debian and Ubuntu branches are identical, and FileArray is built twice |
Duplicate code. | Merge the branches. |
cd /etc/opt/remi or cd /etc/php is not checked |
If the folder is missing, the loop runs over the wrong folder. | Stop if the folder doesn't exist. |
atq and at -c run without sudo |
When not root, only the caller's jobs are visible, so reloads can be scheduled twice. | Run them as root, or use a flag file. |
| The same code is probably in the other commands described as "Read or set PHP ... across all php.ini files" | Fixes must be made in many places. | Move the shared logic into one function. |
See also
| Command | Description |
|---|---|
gzip |
Enable or disable gzip compression in the web server |
fileuploads |
Read or set PHP file_uploads across all php.ini files |
memorylimit |
Change the PHP memory limit for all PHP versions |
maxexecutiontime |
Change the max execution time for all PHP versions |
fpm |
Restart all installed PHP-FPM versions on your server |
reload |
Reload PHP-FPM and the active web server |
checkphpini |
Scan every php.ini for startup errors and remove the offending line |