Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128027 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 4B50E1A00BC for ; Mon, 14 Jul 2025 10:13:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752487907; bh=VLM2q/fYiTmQbndeI47oROqAAMdSf8yBALWvwSkSmvo=; h=From:Date:Subject:To:From; b=Qvg1ibTORfTgLbyVCKK8LDtauzzuPcsZ1YmqXhYwgphy07X54hhC+0R7vqzoOSmrP 3V6mDIFFSjTf8q8Au47aHdrgY+901YsdvbPnziLa0mQq7uILVLcBjtCAQWwiAACwFf 9WMWtEdpd9ILI4aN35W7OWNxY39vQlVSPq4eJUVlCP6/9ieH/XIYCjX1WOXomSQLBJ mHF5Qe7v3naTKloA0/YsXjI3P+tVKjJQsAc9ZbbhlKgG4lmYnecrPsVINJs6BAj35l dPjf05VLmIM8A69jcYD2HfnnpZLGgwyqqw3koTEMMxsXVtpXFH2+VbOV5hqC1gnWIS zQNpD06l3SUZw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0BD36180039 for ; Mon, 14 Jul 2025 10:11:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-ua1-f43.google.com (mail-ua1-f43.google.com [209.85.222.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 14 Jul 2025 10:11:46 +0000 (UTC) Received: by mail-ua1-f43.google.com with SMTP id a1e0cc1a2514c-87f298f3508so1114823241.2 for ; Mon, 14 Jul 2025 03:13:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melroseandco.uk; s=google; t=1752488014; x=1753092814; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=VLM2q/fYiTmQbndeI47oROqAAMdSf8yBALWvwSkSmvo=; b=Ce8pNQYcnwos5Ov1Q+7oyIHl984/6hBXBQMRpGMBlDzlx2gvA/nQvy38PxBnPsLFBC 20sjUNeCxm68Q69ruge6MeRC01QfK8xQHiOdopYR5IQEggLAXuryNVNko+9djbKul2BR zcCQISCugEm6ObS5FGGh8HUead9XjeN3he8iYsW+9F/wBLxcaLl+h5cHESaQK6FRFhy+ ZtET+DIwAe+SZKTy5QRAENBDXbi7yFcdAwjbmV449L7K4qYbumWt31zOxHnBV4V0Pj54 PcKaEjFU7EOkSxI3eU/G8KI262uEZ0SFpFMpt57236SyItsfNd98KNudRlPOIx5qU30G ttIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752488014; x=1753092814; h=content-transfer-encoding:to:subject:message-id:date:from :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VLM2q/fYiTmQbndeI47oROqAAMdSf8yBALWvwSkSmvo=; b=KltndfjpBBP0LPo9U53BDrCeRz3qD7EYoRWSqZQNmn9aSVo6NI06IbmbCHJ+dCePV6 /QaNTyrFxUf9RxRm6izfaTpc0JPiDhGMpoGp6o9uxikeo++dr/RyRNql8a1GfT0D4SLs UjYXFjQHdQ4qP7HFPWmGR9bIuItujFv0yoAS07+1FgVYGNjW2e+qBeOk01nj/IbiUz3x ZsXmabmkDVg+FahH1qFINvsYNxY93Ro22LZQMxqqGhdJXf6Pjh+WCphzlSsbGM/MczS/ NJZzkR9M+uXjs0eDhBvceK6l4mgdqm6IGRY/iUXuwUTT6PO/QXcrws0tSVN1WhSY7pFz R/Lg== X-Gm-Message-State: AOJu0YwA4E3BTNXVbIYB0q/2F0tHiyY740gArV+7hQBVP7qwK7XjcBWw iGJCoT+KELJMANbfso0nePUjG0JHdC8QtXAcdurR31+YsvCGl7fX8LpVgAJwSMV/eT0hqbrMnoc +7PC/SUoGiLGPqsoqrJAsZT+9M/eMl85z4EXNU5pCdyzjQLCk2C3iUHk= X-Gm-Gg: ASbGncvqcL2sNAyxOsDy0Q0gO0DP+xoBQ90ZBCA+USybqN3t8z4gOVonNVqywcHbdi3 LV0nr1AmuIclWfoSCqrEoDttR6pueBQL3ZH5lHtbgQmZxhtu7fhTJoa8xBgGZxfQE+ROFwJEDpz 7oCDQVUlY6JcZcmZNj5DO7u0S0EoK+KTXDEyQ2IrguPYRKedqEt5I1zmShM7YiTiQin4AWG3+Rp jm54g== X-Google-Smtp-Source: AGHT+IFM67OskV2C9Dx6VNHr+e27jc9x07QHefTLHn7ixyNFwzFV+tXZtzTy0DyDU7ohSMZ1vcIeJ2u12t4b29MoqqE= X-Received: by 2002:a05:6102:952:b0:4eb:3f3:bd17 with SMTP id ada2fe7eead31-4f641210b16mr7903675137.2.1752488014020; Mon, 14 Jul 2025 03:13:34 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 14 Jul 2025 11:13:22 +0100 X-Gm-Features: Ac12FXzH4y3pKnqRHao0vnXog0U1ygnqi017ZuvyuRBSkmagPqvT9U3ONQK4OlA Message-ID: Subject: [PHP-DEV] [RFC] Opcache: ABI-based versioning for file cache portability To: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: sam@melroseandco.uk (Samuel Melrose) Hello, Following on from the work to introduce a read-only file cache in #16551, I'd like to propose the next logical step and request feedback on a change to improve opcache's portability in modern containerized environments. This is a pre-RFC discussion to gather initial thoughts on the approach before I proceed with writing a full RFC document. A draft PR implementing the change can be found here: https://github.com/php/php-src/pull/19123 ### The Problem Currently, the opcache file cache is versioned using zend_system_id. While effective for ensuring safety, this ID is highly sensitive to minor changes in the build environment, such as updates to system libraries (e.g., libc) or even patch-level changes in the PHP version itself. This fragility makes pre-generated, read-only opcaches difficult to use reliably in platforms like Google App Engine/Cloud Run, AWS Lambda, or any environment that uses immutable Docker images with automatic base image updates. These updates, while beneficial for security, can change the zend_system_id and needlessly invalidate an otherwise perfectly valid opcache, negating the performance benefits of pre-warming. ### The Proposed Solution To address this, I propose introducing a more stable "ABI hash" for versioning the file cache. During the build process, this change calculates a CRC32 checksum of the header files that define opcache's core data structures (e.g., zend_op, zval, zend_string, zend_function, zend_class_entry, etc.). This hash would then be used as part of the cache key instead of the more volatile zend_system_id. The result is a cache key that only changes when the underlying data structures=E2=80=94the Application Binary Interface (ABI)=E2=80=94actually = change. This typically only happens between minor PHP versions (e.g., 8.5 vs 8.6), not on every patch release or system library update. ### Benefits * Improved Portability: Opcache file caches become portable across builds with identical ABIs, allowing them to be reused across different patch versions of PHP (e.g., 8.3.5 -> 8.3.6) and different base images. * Enhanced Performance on Managed Platforms: This significantly improves the effectiveness of pre-warmed, read-only caches, leading to consistently better cold-start performance and reduced CPU usage in containerized environments. This is the logical continuation of the work on read-only file caches, making them a truly viable solution for high-performance, scalable applications. I would greatly appreciate any feedback on this approach. Is an ABI hash a feasible solution? Are there any potential pitfalls or alternative approaches I should conside= r? Thank you for your time. Samuel Melrose sam@melroseandco.uk +44 (0) 7754096383