Files
php-the-right-way/_posts/14-02-01-Opcode-Cache.md
2023-01-17 23:57:25 +01:00

1.6 KiB

isChild, anchor
isChild anchor
true opcode_cache

Opcode Cache

When a PHP file is executed, it must first be compiled into opcodes (machine language instructions for the CPU). If the source code is unchanged, the opcodes will be the same, so this compilation step becomes a waste of CPU resources.

An opcode cache prevents redundant compilation by storing opcodes in memory and reusing them on successive calls. It will typically check signature or modification time of the file first, in case there have been any changes.

It's likely an opcode cache will make a significant speed improvement to your application. Since PHP 5.5 there is one built in - Zend OPcache. Depending on your PHP package/distribution, it's usually turned on by default - check opcache.enable and the output of phpinfo() to make sure. For earlier versions there's a PECL extension.

Read more about opcode caches: