Add composer dependency on ext-zlib

Created on 9 April 2024, 8 months ago
Updated 12 June 2024, 6 months ago

Problem/Motivation

I am running Drupal 10.0.9 site and would like to upgrade. However it seems that from version 10.1 anything has changed and once I update site I am getting following error:

The website encountered an unexpected error. Please try again later.
Error: Call to undefined function Drupal\Component\Utility\gzcompress() in Drupal\Component\Utility\UrlHelper::compressQueryParameter() (line 87 of core/lib/Drupal/Component/Utility/UrlHelper.php).

Drupal\Component\Utility\UrlHelper::compressQueryParameter() (Line: 111)
Drupal\Core\Asset\CssCollectionOptimizerLazy->optimize() (Line: 167)
Drupal\Core\Asset\AssetResolver->getCssAssets() (Line: 318)
Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAssetLibraries() (Line: 164)
Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments() (Line: 97)
Drupal\big_pipe\Render\BigPipeResponseAttachmentsProcessor->processAttachments() (Line: 72)
Drupal\Core\Render\BareHtmlPageRenderer->renderBarePage() (Line: 76)
Drupal\Core\ProxyClass\Render\BareHtmlPageRenderer->renderBarePage() (Line: 196)
Drupal\system\Controller\DbUpdateController->handle()
call_user_func_array() (Line: 115)
Drupal\Core\Update\UpdateKernel->handleRaw() (Line: 76)
Drupal\Core\Update\UpdateKernel->handle() (Line: 27)

I have tried to update to latest 10.2.5 with no luck so I tried 10.1.8 and finally I have tried with 10.1.0 and found out it all started with this version.

Anyone can help ? (I did not find anything related to this issue on google) and I also tried with a clean version of Drupal 10.1 with the same result so it is not module related.

My Config:
PHP:8.1.25
Apache/2.4.37
Mysql

Steps to reproduce

Install Drupal > 10.1 without the zlib extension

Proposed resolution

Add ext-zlib to composer require

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ“Œ Task
Status

Fixed

Version

11.0 ๐Ÿ”ฅ

Component
Composerย  โ†’

Last updated 28 days ago

No maintainer
Created by

๐Ÿ‡ธ๐Ÿ‡ฐSlovakia coaston

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @coaston
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia mstrelan

    Seems your php version does not have the zlib extension installed.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia mstrelan

    Actually this is a bug, because we don't explicitly declare a dependency on ext-zlib, but installing the extension should resolve this for you.

  • Merge request !7382Add ext-zlib to composer require section โ†’ (Closed) created by mstrelan
  • Status changed to Needs review 8 months ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia mstrelan
  • Pipeline finished with Failed
    8 months ago
    Total: 658s
    #141534
  • ๐Ÿ‡ธ๐Ÿ‡ฐSlovakia coaston

    Hi mstrelan,

    Thank you. However do i need to still install extension for php or this patch/merge can resolve the issue?

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia mstrelan

    Yeah you need to install it. The patch will just prevent people upgrading of they don't have it installed

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    AssetDumper has a check for zlib which we could remove if we are adding a dependency:

    core/lib/Drupal/Core/Asset/AssetDumper.php
    63:    // If CSS/JS gzip compression is enabled and the zlib extension is available
    71:    if (extension_loaded('zlib') && \Drupal::config('system.performance')->get($file_extension . '.gzip')) {
    

    I guess almost everyone must have this extension installed or we would have had more reports along the lines of this one.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia mstrelan

    I guess if we add this in 10.2.x it will just mean folks without zlib will get stuck on 10.2.5 which will also be broken for them. So possibly we need a runtime check in 10.2.6 (or later) to handle it gracefully.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance andypost

    btw that's not that easy to build PHP with zlib extension as shared https://github.com/php/php-src/pull/4681

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    I think we can skip compression when zlip isn't available - it'll mean very long asset query strings but can't really be helped. And then open an 11.x issue to require zlib and remove the checks.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    Actually let's make this the 11.x issue, I'll open an 10.3.x one.

  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    Needs work for #8.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia pradhumanjainOSL

    pradhumanjain2311 โ†’ made their first commit to this issueโ€™s fork.

  • Status changed to Needs review 8 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia pradhumanjainOSL

    Remove zlib as per 8

  • Pipeline finished with Failed
    8 months ago
    Total: 630s
    #141727
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance andypost
  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia mstrelan

    There's an open thread on the MR that I don't know the answer to. Also the build is failing so I obviously didn't follow the correct procedure to update composer.json.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mfb San Francisco

    Requiring zlib doesn't seem like too big of an ask. But has me wondering - I guess there was some reason why it's better to pass all the asset data in long URLs, rather than just storing it persistently and looking it up via the asset file name when needed?

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mfb San Francisco

    @catch the part that confuses me is that asset data is both cached in the cache_data bin, and also sent to the browser in the long query string. I'd have thought one or the other would be sufficient. But, I didn't read thru all the related issues yet, I'm probably missing some basics.

  • First commit to issue fork.
  • Status changed to Needs review 8 months ago
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone

    I ran COMPOSER_ROOT_VERSION=11.x-dev composer update drupal/core to update the lock file. The command is part of this, https://www.drupal.org/about/core/policies/core-dependency-policies-and-... โ†’

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    @mfb the asset generation routes need to be able to independently and reliably generate an asset based on the information on the URL. It would be possible to store the information in in state or key/value so it can't be e.g. evicted from memcache, then only have the lookup key in the URL, but that then creates the potential for a database stampede after cache clears. There's also not a reliable way to know when any particular aggregate would be stale, so the amount of data stored could grow very large over time. The agrcache module in Drupal 7 did things this way, and I think advagg had something similar-ish, but they both had their own problems. The idea to encode the libraries in the URL was from about ten years ago, it took adding the core libraries API and various further optimisations to get there.

    Obviously with the new core solution we've introduced different problems, but IMO they're lesser ones.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mfb San Francisco

    @catch thanks for further explanation. It surprised me to see how many cache_data insert queries run on a cold cache: a "js:..." cache item is inserted during the page load, and further "js:..." and "route:..." cache items are inserted during asset load/generation. So that's why I was thinking the data in the URL could simply be persistently stored and queried rather than passed around. But yes, those cache sets would be a lot more lightweight with a non-database cache backend in place.

  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain penyaskito Seville ๐Ÿ’ƒ, Spain ๐Ÿ‡ช๐Ÿ‡ธ, UTC+2 ๐Ÿ‡ช๐Ÿ‡บ

    AFAIK if we remove the check from AssetDumper, UrlHelper::compressQueryParameter and UrlHelper::uncompressQueryParameter would need to be updated too.

  • Status changed to Needs review 8 months ago
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone

    @penyaskito, yes that needs to be done to.

    I also grepped for zlib and found a few more things to change.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia mstrelan

    I think we need to add the dependency to core/lib/Drupal/Component/Utility/composer.json so that can be used as a standalone library. Might be wrong though, so leaving NR.

  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mfb San Francisco

    I would suggest adding zlib to system_requirements() as well, because of various scenarios such as zlib extension could be disabled after the instance was installed, instance could be moved to an environment without zlib extension, etc.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance andypost

    @mfb there's no reason to add it system_requirements because the extension is bundled into PHP and it's someones hacky attempt to build PHP with zlib as shared extension.

    So it's a waste of CPU for no reason and slowdown for "not fast" page, even #28 suggestion does not make sense as no common way to get PHP without this extension even to make a test

  • Status changed to Needs review 8 months ago
  • Status changed to Postponed 8 months ago
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance andypost

    No reason to waste time on the non-reproducible bug

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia mstrelan

    The page linked in #31 lists zlib in the same category as gd and PDO yet we explicitly list those in composer.json. Is zlib somehow different or can we drop all those too?

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance andypost

    Yes, it means the extension must be available in distribution but I also pointed link in #10 that since PHP 8 there's no way to build PHP with zlib extension as shared (means it it's a separate file and it can be disabled)

    So if someone hacked PHP source for some reason - they they know what are they doing and core must not care about such hacky cases

  • Status changed to Needs review 8 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    I think this change is fine, it is explicit in Composer to try and prevent installs on weird environments and therefore we can remove the runtime checks as well.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    Yeah same here, but #34 is a good reason not to bother with a hook_requirements() entry, which means less to do here.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance andypost

    I'm ++ to removal of useless extension_loaded('zlib') but as the issue marked bug - it should change title/category or provide steps to reproduce

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK
  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mfb San Francisco

    @andypost It's not true that the zlib extension is always bundled into PHP. On FreeBSD, for example, it is a separate package which is installed via pkg install php83-zlib and I'm sure some other distributions work in a similar way. I.e. each distro has its own definition of the PHP package and provides packages for the other extensions.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance andypost

    @mfb I mean it's supposed to be bundled but distro builders can change it with patches.

    Moreover it looks weird what they're doing https://cgit.freebsd.org/ports/tree/archivers/php83-zlib/files/patch-zlib.c
    So the same way you should require hash,PDO and other packages for no reason, just slowdown each composer install with dependencies for 0.5% of users

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mfb San Francisco

    PHP is designed to be configurable at compile time, so patches aren't necessarily needed. You can build with or without various extensions/libraries, whether for running in a memory-constrained environment or any other reason. On the one hand, I'd appreciate if PHP could be guaranteed to be built the same way, but on the other hand I can appreciate it being configurable..

  • Status changed to Needs review 7 months ago
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone
    • longwave โ†’ committed b3a83764 on 11.0.x
      Issue #3439591 by quietone, mstrelan, pradhumanjain2311, andypost, catch...
    • longwave โ†’ committed 0a4f122f on 11.x
      Issue #3439591 by quietone, mstrelan, pradhumanjain2311, andypost, catch...
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    Discussed with @quietone, in order to get the upcoming betas out today we need to commit these today, so committing from NR. Unfortunately we need different patches for each branch, I solved the issues in 11.x and 11.0.x but marking PTBP to get a 10.3.x and 10.4.x patch ready.

    Committed 0a4f122 and pushed to 11.x. Thanks!

    Committed b3a8376 and pushed to 11.0.x. Thanks!

  • Status changed to Downport 7 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK
  • Status changed to Fixed 7 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    @quietone reminded me this is major version only. ๐Ÿ› Skip query string compression if zlib extension isn't available Fixed works around the issue if zlib is not available, but we can still require it to make things simpler in 11.0.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024