APC, XCache, and eAccelerator Available on Shared Hosting

Remember that one time you asked your host for APC or eAceelerator? Most probably they have directed you to their VPS or Dedicated servers because Opcode caching is not compatible with shared hosting. Well, we have to admit we did this too. We did not like it but that was the reality back then. Not anymore!

We are glad to announce the successful implementation of mod_lsapi on all shared hosting servers which will greatly improve your website performance and introduce some great new features. But before we go into this any further, let’s first discuss some common problems, so we can give real context to this announcement.

The Problem

Of course, the ultimate goal when we speak about website optimization is faster page speed and lower resource consumption, so your website can handle more simultaneous visitors without the need to upgrade your plan. Still, every improvement has some sort of trade-off. For example, OpCode Caching such as APC (made obsolete after inclusion of opcache in php 5.5+ ), XCache (only works up to PHP 5.6), and eAccelerator (works up to PHP 5.4) is not compatible with suPHP, which provides a security layer on the shared hosting environment. So, usually the problem is performance, security, compatibility – pick two – you can’t have them all.

Some pretty secure and fast configurations are simply incompatible with some Open Source applications which are a huge problem for the shared hosting environment as different customers use different software platforms to build their websites.

The most secure and user-friendly setup, on the other hand, does not really provide the performance and features we need.

And last but not least, a high-performance host with great compatibility is pretty much useless if it is not secure.

After reviewing a large number of different options and our current infrastructure, we were pretty unhappy with this “pick-two” situation:

  • RUID2 + mod_php – is a giant security hole that lets any user get a root account
  • MPM ITK – is very slow, as it kills processes after each request
  • suPHP & CGI – are both slow, as they start PHP on each request. They are also incompatible with opcode caching.
  • FastCGI – creates a lot of stability issues, hard to configure due to the way it handles processes, and doesn’t use opcode caching optimally.
  • PHP-FPM – needs a socket/startup per customer, not that stable with Apache and creates a mess when we tried to integrate it with PHP Selector – as now PHP selector would have to restart PHP-FPM processes.

What is OpCode Caching

For those of you that are not familiar with opcode caching, OpCache caches are a performance-enhancing extension for PHP. They do this by injecting themselves into the execution lifecycle of PHP and caching the results of the compilation phase for later reuse. It is not uncommon to see a 3x performance increase just by enabling an OpCode cache.

This is achieved by skipping the compilation of already compiled PHP scripts as shown in the diagram below:

What is OpCode Caching Diagram

Almost all of the most popular applications such as Magento, PrestaShop, Boonex Dolphin and Joomla support OpCaches which makes it extremely important to deliver this feature to our customers, so they can get full advantage of both their hosting service and application built-in optimization features.

After a long research process and testing, we decided to implement the CloudLinux solution – mod_lsapi – a new Apache module to serve PHP.

Some of the benefits of mod_lsapi comparing to other ways to serve PHP:

  • Speed – it is faster than any other way to serve PHP with Apache (or at least on cPanel-based host)
  • Stability – it doesn’t suffer from stability issues in process management like PHP-FPM
  • Utilizes full benefits of opcode caching – Yes, you can have APC, eAccelerator, and XCache now!
  • MPM Worker & Event compatible
  • Support for PHP directives in .htaccess files (no more error 500 for you)
  • Drop-in replacement for existing ways to serve PHP (Extremely easy to implement)
  • Fully compatible with PHP Selector – a very important note so you can still change your account PHP version!
  • PHP version can be altered per directory – You can have different PHP versions for different folders of your account!

How Does It Work

mod_lsapi diagram

mod_lsapi is a part of Apache;

Apache passes handling for PHP request to mod_lsapi;

mod_lsapi uses liblsapi to transfers request lsphp daemon;

sulsphp is used to do security checks and start process pool;

lsphp processes request and return data to mod_lsapi;

Each user has lsphp processes in separate CageFS/LVE;

If there are no requests for lsapi_backend_pgrp_max_idle seconds, lsphp process is terminated;

If no lsphp processes available when a new request comes, a new lsphp process is created;

lsphp can process requestslsapi_backend_children simultaneously.

The Conclusion

With the newly deployed setup configuration, all FastComet clients on our shared hosting environment can take full advantage of opcode caching without sacrificing security. Additionally, with the new mod_lsapi, your website should run faster than with any other Apache PHP handler. So far we have tested more than 150 Open Source applications and the results are more than promising. Still, if you experience any difficulties with the new setup or need help to take full advantage of the OpCode caching, feel free to contact our 24/7 technical support. Thanks to the flexible setup we can revert or apply changes per account base so you will never be stuck with one or another solution.

Very soon we will publish full-length tutorials on how to enable all new features and optimize your website performance for the most popular platforms such as Magento, PrestaShop, WordPress, Dolphin and many more so stay tuned for further updates.

Georgi Y.

Georgi has a decade of experience as an executive and entrepreneur in the infrastructure and web hosting space. He is responsible for leading FastComet’s evolution of our scalable cloud, powering the business with Big Data, and linking the latest advances in technology to FastComet’s cloud and IT strategy. As a technical guy, he used his expertise to collect the know-how of creating a reliable and customer friendly hosting company to satisfy the increasing demand of clients.