gzopen()
gzopen() — Open gz-file.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Opens a gzip (.gz) file for reading or writing.
Signature
gzopen(string $filename, string $mode, bool $use_include_path = false): resource|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $filename | string | The file name. |
| $mode | string | As in fopen() (rb or wb) but can also include a compression level (wb9) or a strategy: f for filtered data as in wb6f, h for Huffman only compression as in wb1h. (See the description of deflateInit2 in zlib.h for more information about the strategy parameter.) |
| $use_include_path | bool | If set to true, files in the include_path are searched for too. |
Return value
Returns a file pointer to the file opened, after that, everything you read from this file descriptor will be transparently decompressed and what you write gets compressed. If the open fails, the function returns false.
Example
A runnable snippet:
$fp = gzopen("/tmp/file.gz", "r");
Changelog
| Version | Change |
|---|---|
| 8.5.0 | use_include_path is now of type bool. Previously, it was of type int. |
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page gzopen() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.