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

Aperta
#839 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
php
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
PHP
Stelle
1.7k
Fork
166
Merge medio
1g 1h
PR unite (30g)
38

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di goaop/framework

Tutte le issue di goaop/framework

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.