The Alternative PHP Cache (APC) is a free and open opcode cache for PHP, which we are going to use on iOS, together with lighttpd
in order to cache locally-served pages. We have been using this with dokuwiki in order to speed up the editing of our internal wikis.
This package depends on the Cydia PHP
package and you may also want to install lighttpd
if you have not done so already.
There are two stages involved in setting up the APC cache. First, we need to edit /etc/lighttpd.conf
in order to make sure that it runs in fast-cgi
mode. Next, we are going to add some directives to /usr/lib/php.ini
(which is not at the standard location /etc/php.ini
on iOS) in order to enable the cache.
We need to run lighttpd
in fast-cgi
mode. Following the setup at dokuwiki we add a configuration similar to the following:
fastcgi.server = ( ".php" => ( "localhost" => ( "socket" => "/tmp/php-fastcgi.socket", "bin-path" => "/usr/bin/php-cgi", "min-procs" => 1, "max-procs" => 2, "max-load-per-proc" => 4, "idle-timeout" => 25, # Fix PATH_INFO for PHP scripts that rely on it (like Wordpress). "broken-scriptfilename" => "enable", "allow-x-send-file" => "enable" ) ) )
in order to run lighttpd
in fast-cgi
mode.
The Cydia package will have already added the necessary directives if you have a /usr/lib/php.ini
file. Otherwise, we edit /usr/lib/php.ini
and add the following:
extension=apc.so apc.enabled=1 apc.shm_size=32M apc.ttl=7200 apc.user_ttl=7200 apc.enable_cli=1
To check whether the cache is working properly, the Cydia package includes a file at /usr/include/php/ext/apc/apc.php
. You can copy this file to your web-root and access your device via a browser. As a reference, since we have been fiddling, the following is a screenshot of the APC module running together with lighttpd
and php
:
By default, by installing the package from Cydia, the cache is configured with 32MB
of RAM. Depending on your needs, you may want to adjust this to a higher or lower value by editing /usr/lib/php.ini
. Note that using too much RAM may leave too few for running iOS applications. Be generous but not too generous. 32MB
should be sufficient for most setups.