If your PHP website feels slow despite choosing a decent hosting plan, one of the most common culprits is PHP doing redundant work on every single request. The fastest, cheapest fix — and one that requires zero code changes — is PHP OPcache, an extension bundled with PHP since version 5.5 that most site owners do not know is there.
AsiaGB enables PHP OPcache on every shared hosting server by default
Every AsiaGB shared hosting plan — from the entry tier to the top tier — comes with OPcache pre-configured at the system level. No manual activation needed, no extra cost. Your site benefits from OPcache from day one. Customers can fine-tune individual OPcache settings via DirectAdmin at any time.
What Is PHP OPcache and How Does It Work?
To understand OPcache, you first need to understand what PHP does on every request without it. When a browser asks for a page, PHP must perform these steps for every .php file involved:
- Read the file from disk — PHP opens each
.phpfile from the filesystem. Even with fast SSD storage, reading hundreds of files on every request adds measurable latency. - Tokenize / Lex — PHP reads through the source code character by character and breaks it into a stream of tokens: variable names, operators, keywords, string literals.
- Parse into an AST — The token stream is assembled into an Abstract Syntax Tree that represents the logical structure of the code.
- Compile to Opcodes — The AST is compiled into low-level Opcodes — the instruction set that the Zend Engine (PHP's execution engine) can run directly.
- Execute the Opcodes — The Zend Engine runs the Opcodes and produces the HTML output that is sent back to the browser.
The problem is that steps 1 through 4 happen on every request, every time, even though the code has not changed. A typical WordPress page load involves 300–500 PHP files. On a site with 1,000 daily visitors, that means PHP reads and compiles those same files millions of times per day — wasted CPU cycles on work that produces the same result every time.
OPcache eliminates that waste. After PHP compiles a file to Opcodes for the first time, OPcache stores those Opcodes in a shared memory segment (RAM) that all PHP worker processes can access. On the next request for the same file, PHP skips steps 1 through 4 entirely and pulls the ready-to-execute Opcodes straight from RAM. The result: faster TTFB, lower CPU usage, and more concurrent requests handled on the same hardware.
Core idea: OPcache = an Opcode cache in RAM. PHP skips reading files from disk and recompiling them on every request. The result is lower TTFB, lower CPU load, and higher throughput — without touching a single line of your application code.
Real-World Performance Numbers
Results vary by application, but these are typical ranges measured on PHP workloads:
Applications with many PHP files per request benefit the most: WordPress with many plugins, WooCommerce stores, Laravel applications with a large vendor directory, and Magento installations with thousands of class files. A simple single-file PHP app or a site already served entirely from page cache will see a smaller delta.
What OPcache does not speed up
Understanding the limits of OPcache is as important as knowing its benefits. OPcache only accelerates PHP code execution. If your site is slow for any of these reasons, OPcache cannot help:
- Slow database queries — Fix with proper indexes, query optimization, or an object cache like Redis.
- External API calls — Dependent on the remote server's response time and network latency.
- Large unoptimized images — Compress and resize images at build time or use a CDN.
- Heavy JavaScript bundles — Use bundling, minification, and code splitting on the frontend.
- Client-side network latency — A CDN with edge nodes closer to your visitors reduces this.
AsiaGB: OPcache Active on Every Shared Hosting Server
What sets AsiaGB shared hosting apart from some providers is that OPcache is not an optional add-on or a premium feature — it is enabled at the system level on every single shared hosting server that AsiaGB operates, across every plan tier.
The rationale is straightforward: OPcache benefits customers by making their sites faster, and it benefits the server by reducing CPU load. Lower CPU pressure across all sites on a server means more headroom for traffic spikes and a better experience for everyone sharing that machine. Enabling OPcache system-wide is a win for both sides.
For AsiaGB customers: Your site is already using OPcache from the moment your hosting account is activated. WordPress, Laravel, CodeIgniter, and any PHP application you deploy on AsiaGB shared hosting runs with OPcache enabled. You can optionally override individual settings via DirectAdmin or a .user.ini file to tune for your specific workload.
Settings AsiaGB configures at the system level
AsiaGB pre-configures the core OPcache parameters to values that work well for the shared hosting environment. Customers can override per-account settings through DirectAdmin or .user.ini. Values you may want to customize for your own site:
opcache.max_accelerated_files— Increase this if your WordPress site has many plugins with large PHP codebases.opcache.revalidate_freq— Lower this during active development; raise it on stable production sites.opcache.validate_timestamps— Set to0on production sites that do not change frequently for maximum speed.
How to Verify OPcache Is Running on Your Site
Even though AsiaGB enables OPcache at the system level, it is good practice to confirm it is active and inspect its current state. Here are the main methods:
Method 1: phpinfo()
Create a file called info.php in your web root with this content:
<?php phpinfo();
Open it in a browser and press Ctrl+F to search for "Zend OPcache". If a section with that name is present and opcache.enable shows On, OPcache is running. Look at the "Cached scripts" statistic to see how many files have already been cached.
Important: Delete info.php immediately after you are done. This file exposes your server configuration and PHP version details that attackers could use to target your site.
Method 2: Check status via PHP code
<?php
if (function_exists('opcache_get_status')) {
$s = opcache_get_status();
echo "OPcache enabled: " . ($s['opcache_enabled'] ? 'YES' : 'NO') . "\n";
echo "Cached scripts: " . $s['opcache_statistics']['num_cached_scripts'] . "\n";
echo "Hit rate: " . round($s['opcache_statistics']['opcache_hit_rate'], 2) . "%\n";
echo "Memory used: " . round($s['memory_usage']['used_memory'] / 1048576, 2) . " MB\n";
echo "Memory free: " . round($s['memory_usage']['free_memory'] / 1048576, 2) . " MB\n";
} else {
echo "OPcache not available";
}
Method 3: WordPress plugins
Plugins such as LiteSpeed Cache, W3 Total Cache, or Query Monitor display OPcache status in the WordPress dashboard and include a Flush button — no code needed.
Method 4: DirectAdmin
Log in to DirectAdmin › Select PHP Version › check the Extensions list. If opcache has a checkmark next to the PHP version your site uses, it is enabled for your account.
Tuning OPcache for Your Use Case
The right settings depend on your application. Here are recommended configurations for common scenarios:
Standard WordPress site
opcache.enable=1 opcache.memory_consumption=128 opcache.max_accelerated_files=10000 opcache.revalidate_freq=60 opcache.validate_timestamps=1 opcache.interned_strings_buffer=16 opcache.fast_shutdown=1
WordPress + WooCommerce or large plugin-heavy sites
opcache.enable=1 opcache.memory_consumption=256 opcache.max_accelerated_files=20000 opcache.revalidate_freq=120 opcache.validate_timestamps=1 opcache.interned_strings_buffer=32 opcache.max_wasted_percentage=5
Laravel / Symfony on stable production
opcache.enable=1 opcache.memory_consumption=256 opcache.max_accelerated_files=20000 opcache.revalidate_freq=0 opcache.validate_timestamps=0 opcache.interned_strings_buffer=32 opcache.save_comments=1
Critical: Setting validate_timestamps=0 means OPcache never checks whether source files have changed. You must flush OPcache manually after every deployment, for example by running php artisan opcache:clear or calling opcache_reset(), otherwise PHP continues executing stale compiled bytecode.
| ini directive | What it controls | Recommendation |
|---|---|---|
opcache.enable | Master on/off switch | Always 1 on production |
memory_consumption | MB of RAM allocated for Opcode storage | 128 for typical sites, 256 for WooCommerce/Laravel |
max_accelerated_files | Maximum number of files OPcache will cache | 10000 standard; increase for plugin-heavy WordPress |
revalidate_freq | Seconds between file-change checks | 60 during development; 0 on stable production |
validate_timestamps | Whether to check file modification time at all | 1 during development; 0 on stable production |
interned_strings_buffer | MB for interned (deduplicated) strings in cached code | 16 standard; 32 for large codebases |
max_wasted_percentage | % of wasted memory before a cache restart | 5 (default is fine) |
save_comments | Whether PHP comments/docblocks are preserved in cache | Must be 1 if using Doctrine Annotations or PHP Attributes |
PHP JIT: The Next Level on PHP 8.0+
PHP 8.0 introduced JIT (Just-In-Time Compiler), which works on top of OPcache to push performance even further. The key distinction:
- OPcache alone: Stores pre-compiled Opcodes in RAM so the Zend Engine does not re-read or re-compile source files. The Zend Engine still interprets Opcodes one instruction at a time.
- OPcache + JIT: Translates frequently-executed Opcodes into native machine code that the CPU runs directly — no interpreter layer at all.
Enable JIT by adding these directives (PHP 8.0+):
opcache.jit=on opcache.jit_buffer_size=64M
JIT delivers the largest gains for CPU-intensive work: image processing, mathematical computation, data transformation scripts, and CLI applications. For typical web CRUD applications where the bottleneck is the database rather than CPU, the improvement from JIT is usually small. Benchmark your specific application before enabling JIT in production.
AsiaGB supports PHP 8.0, 8.1, 8.2, and 8.3 on all shared hosting plans. You can switch PHP versions and experiment with JIT settings via DirectAdmin. Contact support if you need help selecting the right PHP version for your application.
How to Override OPcache Settings on DirectAdmin
AsiaGB configures OPcache at the system level, but you can override individual directives for your own account through DirectAdmin or a .user.ini file:
- Log in to DirectAdmin — Your DirectAdmin login URL is typically
yourdomain.com:2222. - Open Select PHP Version — Find this in the Advanced Features or Extra Features section of your dashboard.
- Confirm OPcache is listed as enabled — In the Extensions tab,
opcacheshould already have a checkmark. If not, enable it and save. - Open PHP Options / Settings — Click the Options or Settings tab to access PHP ini overrides for your account.
- Set your values and save — Changes take effect immediately for new PHP requests.
Alternative: .user.ini file — Create a file named .user.ini in your public_html directory and add your OPcache directives there. PHP reads this file automatically within a few minutes (controlled by user_ini.cache_ttl, typically 300 seconds). This approach is handy for deploying configuration changes via version control.
When and How to Flush the OPcache
OPcache holds compiled Opcodes until certain conditions trigger an invalidation. Knowing when to flush manually is important:
Situations that require a manual cache flush
- WordPress Core, plugin, or theme updates — PHP files change; OPcache may still serve old compiled versions.
- Deploying new application code — Especially critical if
validate_timestamps=0. - Editing PHP files directly via FTP or file manager — Flush after saving to ensure the change takes effect.
- Installing or removing caching plugins — These often register hooks that PHP needs to re-compile.
Methods to flush OPcache
| Method | Command / Step | Best for |
|---|---|---|
| PHP function | opcache_reset(); in a protected script | Deployment scripts, CLI automation |
| WordPress plugin | LiteSpeed Cache › Flush OPcache button | Non-developers managing WordPress |
| SSH (if available) | php -r "opcache_reset();" | Developers with SSH access |
| Restart PHP-FPM | DirectAdmin › Restart Services | Emergency full reset |
| Automatic via timestamps | validate_timestamps=1 + revalidate_freq=60 | Sites that update frequently and tolerate a 60-second lag |
Monitoring OPcache Health
On production sites, tracking two OPcache metrics tells you whether the cache is working optimally:
1. Memory usage
If used memory exceeds roughly 80% of the allocated memory_consumption value, OPcache starts evicting cached files, forcing PHP to recompile them. Check with opcache_get_status() and increase memory_consumption if utilization is consistently high.
2. Cache hit rate
A healthy hit rate is above 90%. Below that threshold, files are being evicted too frequently. The fix is either more memory or a reduced max_accelerated_files count so the cache stays within budget.
<?php $s = opcache_get_status(); $stats = $s['opcache_statistics']; echo "Hit rate: " . round($stats['opcache_hit_rate'], 2) . "%\n"; echo "Cached: " . $stats['num_cached_scripts'] . " files\n"; echo "Evicted: " . $stats['num_cached_keys'] - $stats['num_cached_scripts'] . " files\n"; echo "Memory: " . round($s['memory_usage']['used_memory']/1048576,1) . " MB used / " . round($s['memory_usage']['free_memory']/1048576,1) . " MB free\n";
OPcache vs Other Caching Layers: They Are Complementary, Not Alternatives
OPcache is one layer in a complete caching stack. Each layer addresses a different bottleneck:
| Cache type | What it caches | What it speeds up | Examples |
|---|---|---|---|
| OPcache | PHP compiled bytecode (Opcodes) | PHP execution speed | Zend OPcache (built-in) |
| Object Cache | Database query results, computed values | Database round-trips | Redis, Memcached |
| Page Cache | Fully rendered HTML pages | Bypasses PHP entirely (fastest) | LiteSpeed Cache, W3 Total Cache |
| CDN / Edge Cache | Static assets (CSS, JS, images) | Reduces latency via edge nodes near users | Cloudflare, BunnyCDN |
| Browser Cache | Static assets on the client device | Eliminates repeated downloads | Cache-Control headers |
The ideal WordPress performance stack combines all five layers: OPcache for PHP execution → Object Cache (Redis) for database queries → Page Cache for serving pre-built HTML → CDN for static assets → Browser Cache headers. OPcache is the first layer to enable because it is free, has no side effects on most sites, and is already active on all AsiaGB servers.
PHP OPcache: PHP 7.4 vs PHP 8.x
If you are still on PHP 7.4, here is how OPcache compares across versions:
| Feature | PHP 7.4 | PHP 8.0+ |
|---|---|---|
| Core OPcache | Yes — full feature set | Yes — full feature set |
| JIT Compiler | No | Yes (opcache.jit) |
| Preloading | Yes (opcache.preload) | Yes — improved |
fast_shutdown | Must be set to 1 manually | Automatic |
| Security support | End of life Nov 2022 | PHP 8.3 supported until Nov 2026; PHP 8.2 until Dec 2025 |
AsiaGB recommends PHP 8.1 or higher for all new projects. It is faster than PHP 7.x, has longer security support, and unlocks JIT along with other PHP 8 improvements. You can switch your PHP version at any time via DirectAdmin without affecting your site's files.
Troubleshooting Common OPcache Issues
Problem: I edited a PHP file but the change is not showing
OPcache is still serving the old compiled version. Either wait for the revalidate_freq window to expire, call opcache_reset(), or flush via your plugin. If this happens frequently during development, set validate_timestamps=1 and reduce revalidate_freq to a low value like 2.
Problem: My site became slower after enabling OPcache
This is unusual but can happen if memory_consumption is set too low. OPcache runs out of space and evicts frequently, causing constant recompilation. Check the hit rate — if it is below 90%, increase memory_consumption.
Problem: "Cannot allocate memory" errors in PHP logs
OPcache is out of memory. Increase memory_consumption or reduce max_accelerated_files. You can also run opcache_reset() to clear the cache and start fresh.
Problem: Doctrine Annotations / PHP Attributes stopped working
Ensure opcache.save_comments=1 (this is the default). Doctrine and some frameworks read PHP docblock comments at runtime for annotation processing. If comments are stripped from the cache, these frameworks break.
Frequently Asked Questions
Does AsiaGB enable OPcache automatically on shared hosting?
Yes. AsiaGB enables PHP OPcache on every shared hosting server by default across all plans. Customers do not need to turn it on manually or pay extra. Servers are pre-configured with OPcache at the system level. You can further customize settings via DirectAdmin.
Do I need root access to configure OPcache?
No. On DirectAdmin hosting you can adjust OPcache settings through the PHP Version selector in your control panel, or by adding a .user.ini file to your web root, without needing root or SSH access.
What is the difference between OPcache and Redis?
OPcache caches compiled PHP bytecode to accelerate code execution. Redis is an object cache that stores database results and computed data to reduce MySQL queries. They work at different layers and are best used together.
Will OPcache use more RAM?
Yes, OPcache reserves a block of shared memory (typically 128 MB via memory_consumption). On AsiaGB shared hosting, servers are designed with OPcache RAM requirements already accounted for, so it does not count against your account's storage quota.
What is PHP JIT and does AsiaGB support it?
JIT is a PHP 8.0+ feature that compiles frequently-used Opcodes into native machine code for even faster execution. AsiaGB supports PHP 8.0 through 8.3, all of which include JIT. You can enable it via DirectAdmin PHP settings or .user.ini.
Hosting with OPcache Enabled on Every Server
AsiaGB shared hosting comes with PHP OPcache active on all servers from day one — no setup required. PHP 8.x support, SSD storage, 99% uptime, DirectAdmin control panel, and Thai-language support team available daily.
View Hosting Plans