Our web site platform is highly efficient, primarily due to the aggressive caching we have implemented using APC. APC has performance advantages over other systems like Redis and Memcache because it avoids any kind of protocol overhead. It is tightly integrated and allows PHP to access the key-value pairs in memory. However, it comes with the drawback that any command-line PHP does not have access to the same cache because it is running in a different process. This becomes a major issue when there are intensive background processes that are run, and it can become a major source of database load in configuration-heavy systems like Drupal. So how do we leverage the online cache that has been built when working with console applications?

Fork me on GitHubThe common response is that it is not possible: referencereference. Some people have had some success using dumpfiles for opcode caching, which more closely resembles the solution I am considering for accessing the user cache.

Security

Performing system administration via a web-based PHP script requires extra attention to security. To minimize the overhead from security layers, the following techniques are employed/recommended:

  1. The configuration is in a PHP file rather than a YAML/JSON file that could be viewable online.
  2. The console and web parts include a secret key in their handshake. You are responsible for generating the key, but uuidgen is a simple solution.
  3. Most importantly, this script should be installed on a private port so that it cannot be accessed by the public.

Basic Usage: Using User Variable Cache from Console

More features are planned, but the basic usage is simply to access the user variable cache while running a console (command line) PHP script. This is straightforward:

  1. Create a VirtualHost listening on a private port (i.e., NOT 80!)
  2. Clone the ApcConsole repository from github.
  3. Copy settings.php.dist to settings.php and make any customizations - minimally, change the secret.
  4. Include the default handler near the top of your console application:
    require_once "/path-to-private-site/apc-console/index.php";

Tip: Usage with Drush

Add the require_once statement to your module's hook_drush_init() function.

Technologies:


blog comments powered by Disqus