Php – Apache, PHP caching

apachecachingcurlPHP

A have setup an internal proxy kind of thing using Curl and PHP. The setup is like this:

The proxy server is a rather cheap VPS (which has slow disk i/o at times). All requests to this server are handled by a single index.php script. The index.php fetches data from another, fast server and displays to the user.

The data transfer between the two servers is very fast and the bottleneck is only the disk i/o on the proxy server. Since there is only one index.php – I want to know

1) How do I ensure that index.php is permanently "cahced" in Apache on the proxy server? (Googling for php cache, I found many custom solutions that will cache the "data" output by php I want to know if there are any pre-build modules in apache that will cache the php-script itself?).

2) Is the data fetched from the backend server alway in the RAM/cache on the proxy server? (assuming there is enough memory)

3) Does apache read any config files or other files from disk when handling requests?

4) Does apache wait for logs to be written to disk before serving the content – if so I will disable logging on the proxy server (or is there way to ensure content is first served without waiting for logs to be written).?

Basically, I want to eliminate disk i/o all together on the 'proxy' server.

Thanks,

JP

Best Answer

1) Install APC (http://pecl.php.net/apc), this will compile your PHP script once and keep it in shared memory for the lifetime of the webserver process (or a given TTL).

2) If your script fetches data and does not cache/store it on the filesystem, it will be in RAM, yes. But only for the duration of the request. PHP uses a 'share-nothing' strategy which means -all- memory is released after a request. If you do cache data on the filesystem, consider using memcached (http://memcached.org/) instead to bypass file i/o.

3) If you have .htaccess support activated, Apache will search for those in each path leading to your php file. See Why can't I disable .htaccess in Apache? for more info.

4) Not 100% sure, but it probably does wait.