Wiki
 

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
litespeed_wiki:php:opcode_cache [2013/08/07 20:39]
mistwang [APC 3.0.11+]
litespeed_wiki:php:opcode_cache [2016/06/17 14:58] (current)
Jackson Zhang [Popular Opcode Caches]
Line 1: Line 1:
-====== PHP Opcode Caching ​Extensions ​====== +====== PHP Opcode Caching: General Overview ​======
- +
  
-===== APC 3.0.11+ =====+LiteSpeed Web Server allows for effective use of opcode caching with shared hostingBecause Apache does not provide this capability, new LSWS users may want a brief introduction to opcode caching. This wiki will cover the basics of opcode caching — what it does, its limitations,​ and popular opcode caches.
  
-Compile/​Install for Linux, OS X, FreeBSD, Solaris, etc.+===== What is opcode caching? =====
  
-APC is a very mature opcode-caching ​module, aka "php accelerator",  ​and strongly maintained at http://pecl.php.net/apc. We highly recommend APC for anyone using php scripts+Opcode ​caching ​speeds up PHP by caching the compiled opcode of PHP scripts. The server can then use this opcode to respond to requests for a PHP script instead of parsing ​and compiling the source code for each requestThis opcode is stored in shared memory for faster processingAll opcode caches will allow you to set the limit for how much RAM may be allocated to opcode caching.
  
 +===== Opcode caching limitations =====
  
-==== 1) Install ​PHP 4/with LSAPI ====+  - **Opcode caching requires extra RAM.** The RAM limit you set for opcode caching will be automatically partitioned off. You will lose access to this RAM for other uses, so do not allow opcode caching to use too much of your RAM. For example, for a plesk user, normally 128M memory was allowed for that account. opcode cache should be set to 32M or lower. We did see out of memory error when opcode cache memory set to 64M.  
 +  - **Opcode caching requires ​PHP processes be forked from the same parent process in order to share the cache.** If the parent process is killed, the cache is flushed. This is why opcode caching does not work well with Apache'​s suPHP -- suPHP starts a new process for each PHP process, causing opcode cache to be flushed almost as soon as it was created. LiteSpeed'​s [[http://​www.litespeedtech.com/​products/​litespeed-sapi/​php/​suexec-daemon-mode|suEXEC Daemon mode]] and [[http://​www.litespeedtech.com/​products/​litespeed-sapi/​php/​suexec-processgroup|suEXEC ProcessGroup]] have been developed for greater use of opcode caching ​with PHP suEXEC while default suEXEC Worker mode does not. Please [[litespeed_wiki:​php:​enable_opcode_cache|make a change]] during opcode enabling process. 
 +  - **Opcode caches can be buggy.** Many users find that choosing an opcode cache is a matter of trial and error -- different opcode caches work better in different setups. 
 +  - **Opcode caches can cause 503 errors.** This is an extension of the previous point. Opcodes caches are a frequent cause of 503 errors. Try turning off your opcode cache if you're getting 503 errors.
  
-[[litespeed_wiki:​php:​lsapi|Install PHP 4/5 with LSAPI]]+===== Popular Opcode Caches =====
  
-==== 2) Download/​Expand APC 3.0.11+ ​  ==== 
  
-Download and extract source from http://​pecl.php.net/​package/​APC.+  * [[http://​pecl.php.net/​package/​ZendOpcache|Zend Opcache]] -- Actively maintained and supports PHP 5.2 and up. Starting from PHP 5.5,​including 7.0, it is bundled with PHP main source code. 
 +  * [[litespeed_wiki:​php:​apc|APC (Alternative Opcode Cache)]] -- Appears to be discontinued. Supports PHP up to version 5.4, but has been reported buggy with PHP 5.4. May be a good solution for PHP 5.3. APC has opcode cache as well as user/​variable cache. Since PHP 5.5 and PHP 5.6 are unsupported by APC, xCache or Zend Opcache can be alternatives for op-code cache while APCu could be alternative to APC's user cache. 
 +  * [[http://​xcache.lighttpd.net/​|xCache]] -- Actively maintained and supports most PHP versions upto 5.6 but not 7.0.   
 +  * [[http://​eaccelerator.net/​|eAccelerator]] -- Dead project. Supported PHP 5.4 and earlier.
  
-Make sure version 3.0.11 or higher is used. Starting with 3.0.11, --enable-apc will imply --enable-apc-mmap. +How to enable opcode ​caches? ​Please check [[litespeed_wiki:php:enable_opcode_cache|here]].
- +
-In APC source directory do: +
- +
-<​code>​ +
-/​php5install/​php5/​bin/​phpize  +
-./configure --enable-apc --with-php-config=/​php5install/​php5/​bin/​php-config  +
-make  +
-make install +
-</​code>​ +
- +
-==== 3) Configure /​lswsinstall/​conf/​php.ini ==== +
- +
-<​code>​ +
-extension=apc.so  +
-include_path = "​.:/​php5install/​php5"​ +
-;​extension_dir = ./ +
-</​code>​ +
- +
-==== 4) Note ==== +
- +
-You can guage memory usage with the apc.php script provided by the APC package. +
- +
-APC is a drop-in replacement for eAccelerator,​ Turk MMCache, and Zend Accelerator. If you enable APC, you must disable all other opcode ​caching modules or get unexplained 503 errors on startup. ​Please ​note you can use APC with Zend Optimizer which is not an opcode caching module but a code optimizer. +
- +
-If you do get 503 errors, please ​check lsws/​logs/​stderr.log,​ you may need to set "​extension_dir"​ to where apc.so located. +
- +
-==== 5) Memory Saving Tip ==== +
- +
-When configuring PHP LSAPI extapp within LiteSpeed, you can either let LiteSpeed do all the process management, setting "​max_connections"​ = "​instances",​ or let phplsapi spawn a parent process and spawn phplsapi children by setting "​instances"​ = 1 and enter "​PHP_LSAPI_CHILDREN=?"​ in the environment field where ? = "​max_connections"​. By using the PHP_LSAPI_CHILDREN method, only a single APC shared memory slice will be created and shared by all children. Otherwise, PHP will need to create an individual APC memory segment for each PHP process created. +
- +
-==== 6) Trouble Shooting emalloc() errors ==== +
- +
-We have found that the use of APC can artificiallly accelerate PHP's memory usage/​requirement for certain scripts/​operations,​ i.e. deserialize() large serialized packets. This is an issue within APC. +
- +
-We recommend that users of APC/PHP that encounter the emalloc() errors to increase memory ceiling for external processes via LiteSpeed admin: +
- +
-Either server wide: +
-Server > Security > CGI Resource: memory limits (soft/hard) = 200M / 200M +
- +
-Or on per extapp basis: +
-VHost > External Apps > LSAPI App: memory limits (soft/hard) = 200M / 200M +
- +
- +
-Tweak, increase or decrese the values to fit your enviornment to remove emalloc() errros.+
 
litespeed_wiki/php/opcode_cache.1375922345.txt.gz · Last modified: 2013/08/07 20:39 by mistwang