PHP OpCache – worth to use

PHP v5.5 comes with a caching engine named OpCache which stores precompiled scripts in the memory like APC. After the first execution of the scripts, the precompiled script is stored in memory, which will lead to performance boost in your PHP application.

You can find how to enable and configure opcahce in the web. Simply, I want to show you if opcache effects php execution and performance or not.

Test tool:ApacheBench
Number of requests : 300
Threads : 6

OpCache disabled

Concurrency Level: 6
Time taken for tests: 157.911 seconds
Complete requests: 300
Failed requests: 0
Write errors: 0
Non-2xx responses: 300
Total transferred: 92100 bytes
Requests per second: 1.90 [#/sec] (mean)
Time per request: 3158.229 [ms] (mean)
Time per request: 526.372 [ms] (mean, across all concurrent requests)
Transfer rate: 0.57 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 3
Processing: 1020 3145 524.2 3175 4487
Waiting: 1019 3136 524.2 3167 4473
Total: 1021 3146 524.2 3175 4487

OpCache enabled

Concurrency Level: 6
Time taken for tests: 62.019 seconds
Complete requests: 300
Failed requests: 0
Write errors: 0
Non-2xx responses: 300
Total transferred: 92100 bytes
HTML transferred: 0 bytes
Requests per second: 4.84 [#/sec] (mean)
Time per request: 1240.385 [ms] (mean)
Time per request: 206.731 [ms] (mean, across all concurrent requests)
Transfer rate: 1.45 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 3
Processing: 393 1235 263.1 1243 1969
Waiting: 391 1227 262.8 1233 1959
Total: 394 1236 263.1 1245 1969

As you can see OpCache gives a significant performance increase in your php environment.
But you should optimize opcache for different scenarios. You can find more detailed test here

Leave a Reply