Is ZLIB support in PHP enabled by default or NOT?

15,416

Just faced a scenario few days back where I generated the reverse issue as stated by you. The aws linux ami I was working with has a php installation without the zlib configured, due to which I was not getting the zlib package.

I have to re-install the php for the package I wanted i.e. --with-zlib[=DIR] (not recommended, but was a official approach I have to maintain)

So it's not always available by default. Hope that helps.

Share:
15,416
carpics
Author by

carpics

Updated on July 16, 2022

Comments

  • carpics
    carpics almost 2 years

    In the documentation of phpmanual it says:

    Zlib support in PHP is not enabled by default. You will need to configure PHP --with-zlib[=DIR]

    The Windows version of PHP has built-in support for this extension. You do not need to load any additional extensions in order to use these functions.

    So as it says it should be enabled by default only in the Windows version of PHP.

    But I install PHP and Apache on my linux machine from the repository, and then I noticed that it's already enabled. Used those commands:

    sudo apt-get install apache2
    sudo apt-get install php5 php-pear
    

    Does this mean that is also enabled by default if you install PHP from the repository?

    Also I tried to install PHP from source code without adding --with-zlib[=DIR] configuration, just to check will zlib be supported or not. According to documentation on phpmanual it shouldn't.

    I am not expert in compiling so I found tutorial for installing php from source code and I did next steps:

    apt-get install libxml2-dev
    apt-get install build-essential
    
    wget http://in1.php.net/distributions/php-5.3.28.tar.bz
    tar -xvjf php-5.3.28.tar.bz
    cd php-5.3.28
    ./configure --prefix /usr/local/php5
    ------ I configure it without --with-zlib[=DIR]    ---------
    make
    make test
    make install
    

    and as last I run this line to have it work with apache:

    apt-get install libapache2-mod-php5
    

    And after installing PHP on this way ZLIB support was again enabled by default.

    If you are asking yourself how am I checking is it enabled or not, here is the answer.

    I am checking it phpinfo(); and it always says it is enabled:

    enter image description here

    And also I was checking for few function from this library:

    if(function_exists('gzdeflate'))
    {
        echo 'ZLIB is supported';
    }
    else
    {
        echo 'ZLIB is not supported';
    }
    //the result is always 'ZLIB is supported'
    
    if(function_exists('gzencode'))
    {
       echo 'ZLIB is supported';
    }
    else
    {
        echo 'ZLIB is not supported';
    }
    //the result is always 'ZLIB is supported'
    

    I am asking this because I have wordpress plugin. So as plugin it will be installed on many different servers. Now I want to start with using functions gzinflate() and gzdeflate() for one new feature. So I did research and some tests and was confused because documentation says it is not supported by default but when I install PHP on my server it is always supported by default.

    I really need to use those functions but I don't want to use them if it will not be supported on at least 99% of customers servers.

    So is documentation wrong or am I missing something. If I am missing something then can you help me with any alternative functions for compressing which will be supported on at least 99% of servers.