cache:warmup:opcache runs out of memory with the default memory_limit (128M) on larger applications

オープン
#839 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
php
領域
backend

調査の方向性

Start with src/Instrument/ClassLoading/Opcache/FileCachePrimer.php, especially compileFile() and the finally block that restores settings. Check how the primer handles memory_limit while compiling the file set, then add a subprocess test that primes generated files under a low limit such as 32M. Done means the subprocess succeeds and the command explains the memory requirement when the limit is exceeded.

索引モデルが issue の本文から書いたものです。

説明

Bug

Found while building the Docker image of goaop/shop-demo-laravel (php:8.5-cli, Laravel 13.40, goaop-laravel-bridge 2.0.0, framework 4.0.0).

Problem

php artisan aop:warmup-opcache (the framework's cache:warmup:opcache on the application kernel) fails in the official PHP image, whose memory_limit is 128M:

Priming the opcache file cache /var/cache/opcache with 221 files of the AOP cache and 5525 files of the application.
production.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2097152 bytes)
... at /app/vendor/goaop/framework/src/Instrument/ClassLoading/Opcache/FileCachePrimer.php:229

Line 229 is opcache_compile_file($file) in FileCachePrimer::compileFile(). With -d memory_limit=512M the same run compiles 5,599 files. The Symfony demo (about 2,500 files) stayed below 128M.

Cause

The primer runs with opcache.file_cache_only=1, so there is no shared memory. In that mode PHP keeps every script compiled by opcache_compile_file() in the memory of the process until the request ends. Memory grows linearly with the number of files: Composer's class map of a Laravel application already holds about 5,500.

Proposal

  • The primer raises the memory limit for its run when it is lower than needed: ini_set('memory_limit', '-1') or a generous value, restored in the existing finally block that restores the other settings (FileCachePrimer.php:205-211).
  • Or compile in batches in child processes (more robust, more code).
  • In any case, say in the command's help and in the error output when the memory limit is hit.

Acceptance

  • A test (subprocess) that primes more files than fit into a low memory_limit (e.g. -d memory_limit=32M with a few hundred generated files) succeeds.
  • composer test, composer analyse.
主要言語
PHP
スター
1.7k
フォーク
166
平均マージ
1日 1時間
マージ済み PR(30日)
38

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

goaop/framework のほかの issue

goaop/framework の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。