• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

How to Increase Your PHP OPCache Memory

Bhagwad Park

Published on: December 15, 2021

Categories: VPS Hosting 0

Updated: July, 7 2023

If you’re using the latest version of PHP, your site will automatically have OPCache enabled. This is great news for us because we no longer have to install it manually. In this tutorial, I’ll show you how to manage your OP cache and check if it’s working correctly.

Table of Contents
  • What Is OPCache?
    • What Is OPCache Memory?
  • Download and Load the OPCache Monitor PHP File
  • Find and Modify the Right .ini File
  • Restart PHP
  • OPCache Restarts Automatically

What Is OPCache?

PHP is an interpreted language. This means that each line of the script is executed one at a time whenever a PHP file is executed, in contrast to compiled languages, where the code is converted into machine language during compilation. This makes PHP slow. OPCache improves the situation by caching the PHP “bytecode” – a sort of intermediate code between source code and machine code. The latter is specific to a given machine, whereas bytecode works everywhere, but still requires one level of interpretation before it becomes machine-readable. However, it’s much faster to execute bytecode rather than the source code itself.

OPCache caches PHP bytecode the first time any PHP page is executed. This means that subsequent requests for the same PHP file will be much faster.

What Is OPCache Memory?

The compiled bytecode is stored in RAM, and that means you have to be careful how much memory you allot to it. By default, OPCache gets 128 MB of memory. But if you have multiple WordPress sites as I do, you should increase that memory so that there’s enough space for all the bytecode scripts. Here’s how.

Download and Load the OPCache Monitor PHP File

Here’s a great single-file PHP script to monitor OPCache and manage it. Installation is dead simple – merely save the code in a PHP file, upload it to your WordPress directory, point your browser at the file and run it. You’ll see something like this:

OPCache Management Screen
OPCache Management Screen

On the right-hand side, you’ll see the percentage of memory used. If it’s well below 100%, you should be fine – particularly if the “Start time” or “Last reset” fields were some time ago. However, if the memory usage is at or near 100%, then you should increase the OPCache memory so that it has sufficient space to work. Here’s how.

Find and Modify the Right .ini File

In the screenshot above, you’ll see the directory that the OPCache .ini file is using by looking at the “blacklist filename” directive. Open an SSH session and navigate to this folder. Here, you’ll see a .ini file containing the name “opcache”. To edit this file, you’ll need sudo permissions. Once you have the right permissions, open it up and uncomment the following line by removing the hash (#) in front of it:

OPCache Configuration File
OPCache Configuration File

In the above example, I’ve set the OPcache memory to 256 MB, which is double what it was initially. This is because I have three sites running on my VPS, including WP-Tweaks.com, and each of them uses around 25% of my memory.

Save your changes and exit the file.

Restart PHP

Depending on your setup, you should now restart your server and/or PHP. I do both just to be sure. It should take a few seconds and when it’s done, reload the test opcache script you uploaded in the first step. Scroll down and take a look at the “memory consumption” line – it should now reflect the new memory limit you just set.

OPCache Restarts Automatically

OPCache will restart or flush the cache automatically when it has to. Some people think it happens whenever the wasted memory percentage crossed the “max wasted percentage” variable, but this isn’t true. The restart happens whenever the system feels there’s not enough memory. I’m not sure how the wasted percentage factors into the calculation, though.

In short, make sure your OPCache has enough free memory to cache the bytecode of all your PHP files. This will speed up your PHP installation considerably!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Related Posts

How to Use zsh Syntax Highlighting

In an earlier post, we discussed the basics of zsh, what it is, and how to get started. Today we’ll look at syntax highlighting in zsh, its meaning, and how to implement it. I’ll also explain why it doesn’t work well with bash, even though we can get it to work in a “hacky” way. […]

Using Systemctl to Enable Services on Boot on Linux

You can use the systemctl tool to start services automatically on boot. We do this using the "enable" keyword.

All About Bash Parameter Expansion

Parameter expansion in bash is very useful when working with strings like filenames and log entries. It allows you to clean up text.

Bash Signal Handling with Trap: EXIT, ERR, INT

Bash in Linux allows us to set functions that run when certain signals are generated - either by the script, or the shell. Here's how.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA