opcache_compile_file

(PHP 5 >= 5.5.5, PHP 7, PHP 8, PECL ZendOpcache > 7.0.2)

opcache_compile_fileCompila y almacena en caché un script PHP sin ejecutarlo

Descripción

opcache_compile_file(string $filename): bool

Esta función compila un script PHP y lo añade a la caché de opcode sin ejecutarlo. Esto puede ser utilizado para llenar una caché después de un reinicio del servidor precargando los ficheros que van a ser utilizados.

Parámetros

filename

La ruta de acceso al fichero PHP a compilar y almacenar en caché.

Valores devueltos

Devuelve true si filename ha sido compilado con éxito o false en caso de error.

Errores/Excepciones

Si filename no puede ser cargado o compilado, se genera un error de tipo E_WARNING. Puede utilizarse @ para suprimirlo.

Ver también

add a note

User Contributed Notes 1 note

up
19
IceNV
7 years ago
Be aware that opcache will only compile and cache files older than the script execution start.

For instance, if you use a script to generate cache files (e.g. you don't have access to shmop and rely on opcache for in-memory data caching instead), opcache_compile_file will not include the generated file in the cache, because its modification time is after the script start.

The workaround is to use touch() to set a date before the script execution date, then opcache will compile and cache the generated file.
To Top