Cache php opcode caching

How to enable PHP opcode caching

This article describes how to enable PHP opcode caching.

Although many server accounts already have opcode caching enabled by default, some accounts (for example, Turbo Reseller servers) do not.

About APC and OPcache

The Alternative PHP Cache (APC) and OPcache provide opcode caching. By caching the compiled operation codes (opcodes) of PHP scripts, APC and OPcache enable sites to serve page content significantly faster.

APC is a PHP extension that runs on PHP 5.4 and earlier versions. Because it is a separate extension, it may or may not already be installed on your server. For information about how to determine if APC is installed on your server, please see this article.

OPcache is a drop-in replacement for APC that runs on PHP 5.5 and later versions. OPcache is a core component built into PHP, so it does not require separate installation like APC does.

Читайте также:  Param type in java

Enabling opcode caching

To enable opcode caching for your account, follow these steps:

  • Open the PHP Selector:
    • If you are using the Jupiter theme, on the Tools page, in the Software section, click Select PHP Version :
    • If you are using the Paper Lantern theme, in the SOFTWARE section of the cPanel home page, click Select PHP Version :
    • If you are using PHP version 5.4 or older, select apc .
    • If you are using PHP version 5.5 or newer, select opcache .

    More Information

    Article Details

    Источник

    What is OPcache and How Do You Use It?

    You can speed up your WordPress site so it’s around three times faster or more with the OPcache PHP OPcode caching system.

    OPcache is a type of caching system that saves precompiled script bytecode in a server’s memory called a cache, so each time a user visits a web page, it loads faster.

    Here’s more detail on OPcache and how to install it for your WordPress site to speed it up.

    What is Caching?

    Caching is a system you can put in place to speed up your site. It works by saving content to your server’s memory the first time it’s loaded on a web page. Each subsequent page load has the stored content retrieved from memory and served on the page.

    This process means cached content is displayed a lot faster than if it’s loaded directly from the server.

    It’s like memorizing your multiplication tables. Once you have memorized it, it’s so much faster to recite the answer to a multiplication problem from memory rather than trying to calculate the answer all over again.

    A cache works in a similar way. Content is stored in a server’s memory so it can be loaded from there quickly instead of going all the way to the server to load the content which takes more time.

    The result is a faster-loading WordPress website.

    There are also different types of caching such as browser, site, object, and OPcode caching. It’s recommended that you implement more than one kind to increase your site’s performance.

    For details, you can also check out these resources:

    What is OPcache or PHP Opcode Caching?

    OPcache is a type of OPcode caching. This kind of caching compiles human-readable PHP code to code your server understands which is called opcode. This occurs when the PHP file loads on a web page for the first time. Then, it’s saved to the server’s memory for faster loading at each subsequent page visit.

    Bytecode cache engines such as OPcache, APC, and Xcache all complete this process the first time the PHP file is executed without having to do it a second, or third time.

    How PHP Opcode Caching Works

    When a PHP script executes, your server’s cache memory is checked to see if the script has already been cached. If it hasn’t, it’s parsed, which means the code is analyzed.

    Then, the script is compiled into opcode making the file readable by the server. Once that’s done, the opcode is saved to the server’s memory.

    In other words, it’s stored in your server’s cache. The next time a visitor loads the page with the PHP script, the cached code is executed and loaded much faster.

    On the other hand, if the script is loaded on the page and the cache is checked for opcode and finds it, then it’s loaded lickety-split.

    When PHP scripts aren’t in the cache, they’re cached for subsequent page loads.

    The Differences Between OPcache and APC Caches

    OPcache, APC as well as Xcache are all opcode caching systems. OPcache used to be owned by Zend and Alternative PHP Cache (APC) was a free, open-source extension for PHP. Xcache was also an alternative option.

    APC was widely used, but it didn’t have the backing that OPcache had so it could be well maintained and stable with each new PHP release.

    Fortunately, Zend made OPcache open source and available as an extension since PHP version 5.5. In earlier versions, you have the choice to use APC or OPcache, but if you would like to use the latter, you need to manually install it.

    Xcache, on the other hand, is a good alternative to OPcache as a PHP accelerator.

    Will OPcache Speed up My WordPress Site?

    All three options are suitable for WordPress, but the recommended option for PHP version 5.5 and above is OPcache. On average, it speeds up WordPress threefold, at the very least for medium to large sites.

    If you have a smaller site without many additional PHP scripts or plugins installed, you likely won’t notice much of a difference.

    However, you can still install OPcache on even small WordPress sites with no negative effects other than a slight increase in memory usage. But, it won’t be enough to cause any issues. This is similar for medium, large, or enterprise sites.

    How to Install OPcache on Your Server

    If you have PHP version 5.5 and above, OPcache PHP opcode caching is installed and enabled by default. You don’t have to do anything else. There are also no additional requirements or configurations needed to run it.

    That’s also why you won’t find any options if you were to look for them.

    “OPcache can only be compiled as a shared extension. If you have disabled the building of default extensions with –disable-all, you must compile PHP with the –enable-opcache option for OPcache to be available.
    Once compiled, you can use the zend_extension configuration directive to load the OPcache PHP opcode caching extension into PHP. This can be done with zend_extension=/full/path/to/opcache.so on non-Windows platforms, and zend_extension=C:\path\to\php_opcache.dll on Windows.”

    When you have done that, restart PHP using SSH.

    On Apache, enter the command below to restart PHP.

    For Nginx, enter the following:

    How to Install OPcache on Earlier Versions

    If your server is running on PHP versions 5.2, 5.3, or 5.4 you can manually install OPcache using the PECL command below:

    Next, go to you php.ini file:

    You’ll need to update your php.ini file with the following recommended settings:

    You can often find your php.ini file in your site’s file folder system. If you’re not sure how to find it, contact your hosting provider.

    Wrapping Up

    For many WordPress site owners, their server may already have the latest version of PHP installed. This means they already have OPcache automatically enabled to drastically speed up page load times for their site.

    For those who have PHP version 5.2 to 5.4, you can manually install OPcache with the steps outlined above.

    Stay in the loop with the latest WordPress and web performance updates.
    Straight to your inbox every two weeks.

    Источник

    Integrate PHP Opcache & Make Your Application Win Big With Performance

    PHP OPCAHE

    OPcache is an opcode cache that stores precompiled PHP script bytecode in shared memory for faster execution. OPcache will speed up services based on PHP that saves time for your script compiling.

    Best practices for optimizing PHP performance is a way broad topic and I can cover a lot of things in it. Previously I’ve written few guides regarding PHP best practices and firebase integrations which can be beneficial to kickstart with performance issues and database delivery.

    PHP has so many options available which can boost up the application performance and allow handling number of requests smoothly at one time. The one similar option is of PHP OPcache. You can use it numerous times in your PHP apps for making its performance way faster.

    In this article, I’ll give you a brief description about what is OPcache, the benefits of it and steps of integration. More importantly you will see how Cloudways has simplified the PHP OPcache integration in its PHP Hosting server.

    What is OPcache? I Just Heard The Name :/

    Well OPcache comes bundled in PHP 5.5 and is available in latest versions. For previous versions like PHP 5.4, 5.3 and 5.2, you have to install pecl extension first to enable OPcache manually. According to php.net:

    “OPcache improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request.”

    Basically when you complete the code compilation in PHP, the human readable code is converted in to machine language and it takes time to compile all the scripts. So if you make request every time and the cycle continues as the way it is, your app will face lot of performance issues.

    But having the PHP OPcache enabled, the process will run once and cache all the scripts and compile time. The scripts will be stored in memory and only the updates will compile and continue to store. This can give you a serious performance boost and can reduce the app load time significantly. Meanwhile, PHP7 OPcache uses 64MB of memory by default.

    Nothing as Easy as Deploying PHP Apps on Cloud

    With Cloudways, you can have your PHP apps up and running on managed cloud servers in just a few minutes.

    Why The Heck I need OPcache? I’ve Wands

    To answer the above question, let’s consider a case where you have a small website with the normal traffic like 500-5k visitors daily. Concurrent users are also small like 5-10 daily. In this case you won’t feel any major performance issues and the users are entertained perfectly.

    But imagine a website or application with hundred, thousand of visitors per second and the concurrent user ratio is also much more than thousand. Here PHP7 OPcache can give you optimum performance relief as with few configuration steps, you will see serious improvements in speed and performance.

    Here you need to note one more thing that OPcache alone cannot handle everything but your server settings and configuration will also play an important role in it. While your coding structure is also an important part in this case. On a Digitalocean 1GB RAM server with 1 CPU, it can handle 10 request/sec while OPcache is disabled. By enabling it the number will increase to 34+ request/sec. You can also optimize it further to boost app performance more.

    A case at stackoverflow

    While researching on OPcache, I found an interesting case regarding the performance benchmark of OPcache on a website and also have updated about the PHP benchmarks. A user Tschallacka has defined his config on the server and how the request has been served in small time. The case will let you know how OPcache enhances application’s speed and performance.

    “I have made an extensive framework with a lot of fields and validation methods and enums to be able to talk to my database.

    When using this script without OPcache, I push 9000 requests in 2.8 seconds to the Apache server. It maxes out at 90-100% CPU for 70-80 seconds until it catches up with all the requests.

    Total time taken: 76085 milliseconds(76 seconds)

    With OPcache enabled, it runs at 25-30% CPU time for about 25 seconds and never passes 25% CPU use.

    Total time taken: 26490 milliseconds(26 seconds)

    I have made an OPcache blacklist file to disable the caching of everything except the framework which is all static and doesn’t need changing of functionality. I choose explicitly for just the framework files so that I could develop without worrying about reloading/validating the cache files. Having everything cached saves a second on the total of the requests 25546 milliseconds

    This significantly expands the amount of data/requests I can handle per second without the server even breaking a sweat.

    Источник

  • Оцените статью