Diferencia entre revisiones de «OPcache»

De MoodleDocs
(tidy up)
(Updated as per 3.5 page)
Línea 1: Línea 1:
{{Versiones|Esta página es acerca de OPcache '''para Moodle 3.5''' y más modernos. Para la documentación anterior,  vaya a '''[[34/OPcache]]''' y '''[[29/OPcache]]''' .}}{{Entorno}}
{{Versiones|Esta página es acerca de OPcache '''para Moodle 3.5''' y más modernos. Para la documentación anterior,  vaya a '''[[34/OPcache]]''' y '''[[29/OPcache]]''' .}}{{Entorno}}


La extensión estándar OPCache está altamente recomendada; desde Moodle 2.6, es la única solución soportada oficialmente por los desarrolladores de PHP. Los beneficios son aumento del desempeño y significativamente menor uso de memoria.  
La extensión estándar OPCache está altamente recomendada; desde Moodle 2.6, es la única solución soportada oficialmente por los desarrolladores de PHP. Los beneficios son aumento del desempeño y significativamente menor uso de memoria. Sin embargo, las extensiones para cacheo de ''opcode'' (incluyendo OPcache, eAccelerator y APC) no son compatibles con los servidores configurados para usar algunos tipos comunes de manejadores PHP de alta seguridad, tales como suPHP (que se emplea por defecto en servidores Linux WHM / cPanel ). Esto es muy comun en servidores compartidos.
 
Sin embargo, las extensiones para cacheo de ''opcode'' (incluyendo OPcache, eAccelerator y APC) no son compatibles con los servidores configurados para usar algunos tipos comunes de manejadores PHP de alta seguridad, tales como suPHP (que se emplea por defecto en servidores Linux WHM / cPanel ). Esto es muy comun en servidores compartidos.


==Instalación==
==Instalación==
Línea 13: Línea 11:


==Configuración==
==Configuración==
Configuraciones en PHP.ini :


<code ini>
<code ini>
Línea 20: Línea 16:
opcache.enable = 1
opcache.enable = 1
opcache.memory_consumption = 128
opcache.memory_consumption = 128
opcache.max_accelerated_files = 2000
opcache.max_accelerated_files = 10000
opcache.revalidate_freq = 2
opcache.revalidate_freq = 60


; Requerido para Moodle
; Required for Moodle
opcache.use_cwd = 1
opcache.use_cwd = 1
opcache.validate_timestamps = 1
opcache.validate_timestamps = 1
Línea 29: Línea 25:
opcache.enable_file_override = 0
opcache.enable_file_override = 0


; Si algo no funciona en Moodle
; If something does not work in Moodle
;opcache.revalidate_path = 1 ; Puede arreglar problemas con rutas ''include''
;opcache.revalidate_path = 1 ; May fix problems with include paths
;opcache.mmap_base = 0x20000000 ; (Windows solamente) corrije caídas de OPcache (''crashes'') con event id 487
;opcache.mmap_base = 0x20000000 ; (Windows only) fix OPcache crashes with event id 487


; Experimental para Moodle 2.6 y posteriores
; Experimental for Moodle 2.6 and later
;opcache.fast_shutdown = 1
;opcache.fast_shutdown = 1
;opcache.enable_cli = 1 ; Acelera CLI cron
;opcache.enable_cli = 1 ; Speeds up CLI cron
;opcache.load_comments = 0 ; Puede disminuir el uso de memoria, puede no ser compatible con complementos y otras apps.
;opcache.load_comments = 0 ; May lower memory use, might not be compatible with add-ons and other apps.
</code>
</code>


Al usar plataformas no-Windows, Usted tiene que usar la configuración de ''zend_extension'' para cargar la extensión OPcache en PHP al añadirla a php.ini:
When using non-Windows platforms, you have to use the ''zend_extension'' configuration to load the OPcache extension into PHP by adding to php.ini.
<code ini>
<code ini>
zend_extension=/ruta/completa/hacia/opcache.so  
zend_extension=/full/path/to/opcache.so  
</code>
</code>


 
When using IIS you will need PHP 5.5 and you will need to add the extension for opcache under the ''ExtensionList'' section of the php.ini file. For PHP 5.3 and 5.4 you can download the binaries separately from [http://windows.php.net/downloads/pecl/releases/opcache] and you will also need to enter full absolute path to the module dll in php.ini.
Al usar IIS Usted necesitará PHP 5.5 y Usted necesitará añadir la extensión para opcache bajo de la sección de ''ExtensionList'' del archivo php.ini. Para PHP 5.3 y 5.4 Usted puede descargar los archivos binarios por separado desde [http://windows.php.net/downloads/pecl/releases/opcache] y Usted también necesitará escribir la ruta absoluta completa al dll del módulo en php.ini.


<code ini>
<code ini>
Línea 52: Línea 47:
zend_extension=php_opcache.dll
zend_extension=php_opcache.dll
</code>
</code>
; memory_consumption
; memory_consumption
From: [https://jpauli.github.io/2015/03/05/opcache.html PHP's OPCache extension review]
From: [http://blog.jpauli.tech/2015/03/05/opcache.html PHP's OPCache extension review]
*''The size of the memory segment can be told using the opcache.memory_consumption INI setting (Megabytes). Size it big, don't hesitate to give space. Never ever run out of shared memory space, if you do, you will lock your processes, we'll get back to that later.''
*''The size of the memory segment can be told using the opcache.memory_consumption INI setting (Megabytes). Size it big, don't hesitate to give space. Never ever run out of shared memory space, if you do, you will lock your processes, we'll get back to that later.''


*''Size the shared memory segment according to your needs, don't forget that a production server dedicated to PHP processes may bundle several dozens of Gigabytes of memory, just for PHP. Having a 1Gb shared memory segment (or more) is not uncommon, it will depend on your needs, but if you use a modern application stack, aka framework based, with lots of dependencies etc... , then use at least 1Gb of shared memory.''
*''Size the shared memory segment according to your needs, don't forget that a production server dedicated to PHP processes may bundle several dozens of Gigabytes of memory, just for PHP. Having a 1Gb shared memory segment (or more) is not uncommon, it will depend on your needs, but if you use a modern application stack, aka framework based, with lots of dependencies etc... , then use at least 1Gb of shared memory.''


Having that in mind, set opcache.memory_consumption to a value high enough to avoid filling it up (as long as your RAM usage allows you to), and then monitor the OPCache to adjust that value to its optimal size.
Having that in mind, set opcache.memory_consumption to a value high enough to avoid filling it up (as long as your RAM usage allows you to), and then monitor the OPCache to adjust that value to its optimal size. As the total size of the PHP files in a standard Moodle 3.5 is almost 90MB, setting this value higher than that can be a good idea. Take into account that the PHP files of the plugins and those on the MoodleData folder (language pack files...) also count, so these values can be different on each installation. If you have several instances of Moodle you should multiply that value by the number of instances.
; max_accelerated_files
{{Nota|Solamente para Moodle 2.9 y anteriores, arriba se recomienda que opcache.max_accelerated_files se ajuste en 4000. Para Moodle 3.0 ajustar a 8000.}}
De: [http://php.net/manual/en/opcache.configuration.php#ini.opcache.max-accelerated-files php.net max-accelerated-files]
*''The maximum number of keys (and therefore scripts) in the OPcache hash table. The actual value used will be the first number in the set of prime numbers { 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987 } that is bigger than the configured value. Only numbers between 200 and 100000 are allowed.''


{{Nota|Solamente para Moodle 2.9 y anteriores, al configurar max_accelerated files a 4000 se permitirá que 7963 archivos PHP sean cacheados en la tabla ''hash''. Mientras que esto puede ser una recomendación apropiada para muchas instalaciones, existen aproximadamente ~7000 archivos PHP en el núcleo de Moodle 2.7. Si su versión de Moodle usa muchos plugins adicionales (complementos), o si por alguna razón su número total de archivos PHP cacheados en cobertura es probable que excedan de 7963, valdría la pena aumentar este número. Yo (el autor en inglés) sugeriría que la recomendación por defecto fuera de 8000 en lugar de 4000. (O, de hecho, usar uno de los números  (-1) en el conjunto primario de arriba.)}}
Tip: If using Linux, you can know the total size of the PHP files of a folder using this command:
<code ini>
find ./ -type f -name "*.php" -printf "%s\n" | gawk -M '{t+=$1}END{print t}' | numfmt --to=si
</code>


{{Moodle 3.0}}
; max_accelerated_files
Como Moodle 3.0 contiene más de 8000 archivos PHP, se recomienda arriba que opcache.max_accelerated_files se configure a 8000 para acomodar ésto (en realidad se usará 16229 para la explicación superior).
From: [http://php.net/manual/en/opcache.configuration.php#ini.opcache.max-accelerated-files php.net max-accelerated-files]
*''The maximum number of keys (and therefore scripts) in the OPcache hash table. The actual value used will be the first number in the set of prime numbers { 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987 } that is greater than or equal to the configured value. The minimum value is 200. The maximum value is 100000 in PHP < 5.5.6, and 1000000 in later versions.''


{{Moodle 3.3}}
As Moodle 3.5 contains almost 10.000 php files it is recommended above that opcache.max_accelerated_files should be set to 10000 to accommodate this (16229 will actually be used as per the explanation above). If you have several instances of Moodle you should multiply that value by the number of instances.
Como Moodle 3.0 contiene más de 9000 archivos PHP, se recomienda arriba que opcache.max_accelerated_files se configure a 8000 para acomodar ésto (en realidad se usará 16229 para la explicación superior). Si Usted tiene varias instancias de Moodle Usted debería de multiplicar este valor por el número de instancias.
 
Si se instalan muchos plugins adicionales, de forma tal que su  total de archivos PHP excediera de 16229 entonces debería de usarse el siguiente valor más apropiado para max_accelerated_files.


If many additional plugins are installed so that your total PHP files exceed 16229 then the next most suitable value for max_accelerated_files should be used.
Tip: If using Linux, you can know the total PHP files of your Moodle using this command:
<code ini>
find ./ -type f | grep -E ".*\.php$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort | uniq -c | sort -n
</code>
==Vea también==
==Vea también==
* [http://pecl.php.net/package/ZendOpcache PECL ZendOPcache]
* [http://pecl.php.net/package/ZendOpcache PECL ZendOPcache]

Revisión del 13:46 4 sep 2018

note icon.png Existe documentación diferente para varias versiones de Moodle: Esta página es acerca de OPcache para Moodle 3.5 y más modernos. Para la documentación anterior, vaya a 34/OPcache y 29/OPcache .


La extensión estándar OPCache está altamente recomendada; desde Moodle 2.6, es la única solución soportada oficialmente por los desarrolladores de PHP. Los beneficios son aumento del desempeño y significativamente menor uso de memoria. Sin embargo, las extensiones para cacheo de opcode (incluyendo OPcache, eAccelerator y APC) no son compatibles con los servidores configurados para usar algunos tipos comunes de manejadores PHP de alta seguridad, tales como suPHP (que se emplea por defecto en servidores Linux WHM / cPanel ). Esto es muy comun en servidores compartidos.

Instalación

La extensión OPcache es distribuída como parte de PHP 5.5.0 y posteriores. Está disponible también para versiones estables más antiguas de PHP desde PECL bajo el nombre original ZendOPcache.

NOTA: Si Usted está corriendo PHP 5.3 o 5.4 Usted puede ignorar con seguridad el mensaje de revisión del Entorno sobre OpCache. Sin embargo, se recomienda que actualice PHP a 5.5 o posterior; debido a los muchos problemas descritos con PHP 5.2 y 5.3, donde el actualizar PHP resultó ser la solución más sencilla.


Configuración

[opcache] opcache.enable = 1 opcache.memory_consumption = 128 opcache.max_accelerated_files = 10000 opcache.revalidate_freq = 60

Required for Moodle

opcache.use_cwd = 1 opcache.validate_timestamps = 1 opcache.save_comments = 1 opcache.enable_file_override = 0

If something does not work in Moodle
opcache.revalidate_path = 1 ; May fix problems with include paths
opcache.mmap_base = 0x20000000 ; (Windows only) fix OPcache crashes with event id 487
Experimental for Moodle 2.6 and later
opcache.fast_shutdown = 1
opcache.enable_cli = 1 ; Speeds up CLI cron
opcache.load_comments = 0 ; May lower memory use, might not be compatible with add-ons and other apps.

When using non-Windows platforms, you have to use the zend_extension configuration to load the OPcache extension into PHP by adding to php.ini. zend_extension=/full/path/to/opcache.so

When using IIS you will need PHP 5.5 and you will need to add the extension for opcache under the ExtensionList section of the php.ini file. For PHP 5.3 and 5.4 you can download the binaries separately from [1] and you will also need to enter full absolute path to the module dll in php.ini.

[ExtensionList] ... zend_extension=php_opcache.dll

memory_consumption

From: PHP's OPCache extension review

  • The size of the memory segment can be told using the opcache.memory_consumption INI setting (Megabytes). Size it big, don't hesitate to give space. Never ever run out of shared memory space, if you do, you will lock your processes, we'll get back to that later.
  • Size the shared memory segment according to your needs, don't forget that a production server dedicated to PHP processes may bundle several dozens of Gigabytes of memory, just for PHP. Having a 1Gb shared memory segment (or more) is not uncommon, it will depend on your needs, but if you use a modern application stack, aka framework based, with lots of dependencies etc... , then use at least 1Gb of shared memory.

Having that in mind, set opcache.memory_consumption to a value high enough to avoid filling it up (as long as your RAM usage allows you to), and then monitor the OPCache to adjust that value to its optimal size. As the total size of the PHP files in a standard Moodle 3.5 is almost 90MB, setting this value higher than that can be a good idea. Take into account that the PHP files of the plugins and those on the MoodleData folder (language pack files...) also count, so these values can be different on each installation. If you have several instances of Moodle you should multiply that value by the number of instances.

Tip: If using Linux, you can know the total size of the PHP files of a folder using this command: find ./ -type f -name "*.php" -printf "%s\n" | gawk -M '{t+=$1}END{print t}' | numfmt --to=si

max_accelerated_files

From: php.net max-accelerated-files

  • The maximum number of keys (and therefore scripts) in the OPcache hash table. The actual value used will be the first number in the set of prime numbers { 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987 } that is greater than or equal to the configured value. The minimum value is 200. The maximum value is 100000 in PHP < 5.5.6, and 1000000 in later versions.

As Moodle 3.5 contains almost 10.000 php files it is recommended above that opcache.max_accelerated_files should be set to 10000 to accommodate this (16229 will actually be used as per the explanation above). If you have several instances of Moodle you should multiply that value by the number of instances.

If many additional plugins are installed so that your total PHP files exceed 16229 then the next most suitable value for max_accelerated_files should be used. Tip: If using Linux, you can know the total PHP files of your Moodle using this command: find ./ -type f | grep -E ".*\.php$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort | uniq -c | sort -n

Vea también

Forum discussions: