Knowledgebase

PHP OPcache Configuration

OPcache is a caching engine for PHP that improves the performance of PHP scripts by storing precompiled script bytecode in shared memory. WHM cPanel provides a user-friendly interface to configure and manage OPcache settings. This knowledge base will guide you through the process of optimizing and fine-tuning PHP OPcache for your server.

  1. Accessing PHP Configuration in WHM:

    • Log in to WHM.

    • Navigate to 'Software' and click on 'MultiPHP INI Editor'.

  2. Selecting the PHP Version:

    • Choose the PHP version you wish to configure from the dropdown menu.

    • Click 'Edit'.

  3. Locating OPcache Settings:

    • Scroll down or use the search function to find OPcache-related configurations.

  4. Enabling OPcache:

    • Set opcache.enable to On to enable OPcache.

    • This is usually the default setting.

  5. Configuring OPcache Memory Allocation:

    • Adjust opcache.memory_consumption to allocate an appropriate amount of memory for OPcache.

    • Be cautious not to allocate too much, as it may lead to memory exhaustion.

  6. Setting OPcache Interned Strings Buffer:

    • opcache.interned_strings_buffer defines the amount of memory for storing interned strings.

    • A higher value can lead to better performance for scripts with a lot of string manipulation.

  7. Adjusting OPcache Max Accelerated Files:

    • opcache.max_accelerated_files specifies the maximum number of scripts that can be stored in the cache.

    • Increase this value if you have a large number of PHP files.

  8. Configuring OPcache Validation Frequency:

    • opcache.validate_timestamps controls how often OPcache checks for changes in PHP files.

    • Setting it to 1 forces OPcache to validate timestamps on every request.

  9. Setting OPcache Revalidate Frequency:

    • opcache.revalidate_freq determines how often OPcache checks the file system for changes.

    • A lower value means more frequent checks, which may impact performance.

  10. Fine-tuning OPcache Optimization Level:

    • opcache.optimization_level defines the level of optimization applied to scripts.

    • Higher levels may improve performance, but at the cost of longer initial compile times.

  11. Configuring OPcache Fast Shutdown:

    • opcache.fast_shutdown can be set to On for faster shutdowns.

    • It may improve PHP process termination times.

  12. Utilizing OPcache Blacklist:

    • opcache.blacklist_filename allows you to specify a file containing a list of files that should not be cached.

    • Useful for excluding specific scripts from OPcache.

  13. Setting OPcache Preloading (Optional):

    • PHP 7.4+ supports preloading, which allows you to load and cache scripts at startup.

    • Use opcache.preload to specify a preload file.

  14. Monitoring OPcache Statistics:

    • You can view OPcache statistics by using PHP functions or extensions like Zend OPcache GUI.

  15. Restarting Apache after Configuration:

    • After making changes, it's recommended to restart Apache to apply the new OPcache settings.

  16. Testing and Benchmarking:

    • Use benchmarking tools to assess the impact of your OPcache configuration changes on PHP script performance.

  17. Common Troubleshooting:

    • If encountering issues, ensure there are no conflicting configurations in .htaccess files or elsewhere.

  18. Regular Maintenance:

    • Periodically review and adjust OPcache settings based on your server's requirements and traffic patterns.

Conclusion:

Optimizing PHP OPcache is a critical step in enhancing the performance of PHP applications on your server. By following the steps outlined in this knowledge base, you can configure OPcache settings in WHM cPanel to best suit your server's needs. Regular monitoring and fine-tuning will ensure optimal PHP script execution for your websites and applications.

  • 0 Users Found This Useful
Was this answer helpful?