Introduction
OPcache is one of the most critical extensions for PHP performance. It caches compiled PHP scripts in shared memory, eliminating the need to recompile on every request. While OPcache is enabled by default in PHP 8.5, its default settings may not be optimal for your application.
In this benchmark, we test three key OPcache parameters:
opcache.memory_consumption– how much memory to use for cachingopcache.max_accelerated_files– how many files to cacheopcache.revalidate_freq– how often to check for file changes
We test these parameters across three scenarios:
- Pure PHP CPU‑intensive script (recursive Fibonacci + 1M loop)
- WordPress homepage (I/O‑bound, 100 posts, 500 comments)
- Laravel CPU route (framework‑heavy, same Fibonacci task)
All tests use PHP 8.5.2 with JIT disabled to isolate OPcache effects.
Test Environment
| Component | Specification |
|---|---|
| CPU | Intel Xeon Platinum (4 vCores) |
| RAM | 8 GB ECC |
| OS | Ubuntu 24.04 LTS |
| Web Server | Nginx 1.24 |
| PHP Version | 8.5.2 |
| PHP‑FPM | Static, pm.max_children = 100 |
| OPcache | Enabled, JIT disabled |
| Test Tool | Apache Bench (ab) |
| Concurrency | 1 (single request) |
| Requests per Run | 1,000 |
| Warm‑up | 500 requests before each run |
Results
Parameter 1: opcache.memory_consumption
| Memory | CPU (req/s) | WordPress (req/s) | Laravel (req/s) |
|---|---|---|---|
| 64 MB | 10.38 | 9.36 | 8.80 |
| 128 MB | 10.16 | 9.36 | 8.39 |
| 256 MB | 10.23 | 9.36 | 8.67 |
| 512 MB | 10.58 | 9.37 | 9.23 |
- CPU script: Throughput increases with more memory, peaking at 512 MB.
- WordPress: Almost no change across values – I/O‑bound sites see little benefit.
- Laravel: Clear improvement from 8.39 req/s (128 MB) to 9.23 req/s (512 MB), a 10% gain.
Recommendation: Set opcache.memory_consumption = 512 for Laravel/Symfony apps, or at least 256 MB for general use.
Parameter 2: opcache.max_accelerated_files
| Max Files | CPU (req/s) | WordPress (req/s) | Laravel (req/s) |
|---|---|---|---|
| 2,000 | 10.57 | 9.37 | 8.77 |
| 5,000 | 10.34 | 9.37 | 8.99 |
| 10,000 | 10.49 | 9.38 | 9.19 |
| 20,000 | 10.80 | 9.37 | 9.27 |
- CPU: Slight improvement at 20,000 files (10.80 req/s).
- WordPress: Unaffected – few files, default is enough.
- Laravel: Steady increase from 8.77 to 9.27 req/s – +5.7%.
Recommendation: Set opcache.max_accelerated_files = 20000 for modern frameworks. For WordPress-only, 5000 is sufficient.
Parameter 3: opcache.revalidate_freq
| Revalidate (sec) | CPU (req/s) | WordPress (req/s) | Laravel (req/s) |
|---|---|---|---|
| 0 (always) | 10.65 | 9.38 | 8.75 |
| 2 | 10.56 | 9.37 | 9.39 |
| 60 | 10.79 | 9.35 | 9.39 |
| 300 | 10.53 | 9.37 | 9.15 |
- CPU: 60 seconds gives the best result (10.79 req/s).
- WordPress: All values nearly identical.
- Laravel: Noticeable drop at
revalidate_freq = 0(8.75 req/s) – constant file checks hurt performance. Values 2 and 60 perform equally well (9.39 req/s).
Recommendation: Set opcache.revalidate_freq = 60 for production (slightly better CPU). Use 0 only during active development (immediate file changes) – but note it slows down Laravel.
Optimal Configuration Summary
| Environment | memory_consumption | max_accelerated_files | revalidate_freq |
|---|---|---|---|
| Development | 128 MB | 10000 | 0 |
| Small WordPress | 128 MB | 5000 | 2 |
| Medium/Large WordPress | 256 MB | 10000 | 60 |
| Laravel / Symfony | 512 MB | 20000 | 60 |
General‑purpose (balanced):
ini
opcache.memory_consumption = 256
opcache.max_accelerated_files = 20000
opcache.revalidate_freq = 60How to Apply These Settings
Edit your php.ini (or php-cli.ini for CLI):
ini
; OPcache core settings
opcache.enable = 1
opcache.enable_cli = 1
; Optimized for Laravel / Symfony
opcache.memory_consumption = 512
opcache.max_accelerated_files = 20000
opcache.revalidate_freq = 60
; Optional but recommended
opcache.interned_strings_buffer = 16
opcache.fast_shutdown = 1After changes, restart PHP-FPM:
bash
/etc/init.d/php-fpm-85 restartVerify with phpinfo() or:
bash
php -r "print_r(opcache_get_status(false));"Key Takeaways
- memory_consumption matters most for framework‑heavy apps – 512 MB gives a measurable boost.
- max_accelerated_files should be high enough to cache all your PHP files. For Laravel, 20,000 is safe.
- revalidate_freq = 60 seconds balances performance and update detection. Avoid 0 – it hurts Laravel.
- WordPress is I/O‑bound – OPcache tuning has minimal impact on its frontend.
Frequently Asked Questions
A: Check opcache_get_status()['memory_usage']['free_memory']. If near zero, increase memory_consumption.
A: Compare opcache_statistics['num_cached_scripts'] with your setting. If they’re close, increase it.
A: No – it forces PHP to check every file on every request, killing performance. Use 60+ seconds.
A: Yes, OPcache parameters are identical across PHP 8.x.
Test Scripts (for Reproducibility)
Important: Run these commands only on your own isolated test server.
bash
# Pure CPU script
ab -n 1000 -c 1 https://phpbenchlab.com:8080/test.php
# WordPress homepage
ab -n 1000 -c 1 https://phpbenchlab.com:8084/
# Laravel CPU route
ab -n 1000 -c 1 https://phpbenchlab.com:8085/cpu-testFull test scripts are available in our previous benchmarks.
Conclusion
OPcache tuning can significantly improve PHP performance, especially for framework‑based applications:
- CPU‑intensive tasks: Up to 10% gain with optimal settings.
- Laravel: Up to 10% gain from memory and file limit increases.
- WordPress: Minimal impact – focus on database and page caching instead.
Use our recommended configuration as a starting point, then monitor your opcache_get_status() to fine‑tune for your specific workload.
OPcache tuning is just one of the four pillars covered in our complete PHP optimization guide, which also addresses JIT configuration, application server selection, and I/O latency strategies.
All raw data and methodology are provided. Reproduce this benchmark on your own hardware to validate results.
I’ve been exploring for a little bit for any high-quality articles
or blog posts in this sort oof house . Exploring
in Yahoo I finally stumbled upon this website. Studying this info So i am glad to show that I’ve a
very good uncanny feeling I discovered just what I
needed. I such a lot indubitably will make
certain to don?t disregard this website
and give it a look regularly.
Thank you for liking it