Reputation: 4808
As i am new to PHP i have some question about internal that i am not able to find exactly on internet.
I have read a statement
PHP recompiles your program every time that it is run into an machine readable language, called opcodes. An opcode cache stores the compilation in memory and just re-executes it when called a second time.
so some question arises in my mind-
I read somewhere that PHP cache the OPCODE so that no need to recompile. How can i get to know that if any opcaode caching technique is enabled or not on my server? i am using Xampp with default configuration on my local machine windows.
Does PHP uses OPCODE caching by default or we have to enable it by installing any external library?
Upvotes: 3
Views: 2050
Reputation: 4808
OPcache improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request.
phpinfo() wont show any status of the OPcache if the Zend OPcache extension is not loaded. To check whether is Zend OPcache loaded or not you can use
print_r(get_loaded_extensions());
If Zend OPcache is not listed in the array you can configure it in php.ini file
Just add in php.ini
[opcache]
zend_extension ="D:\xampp\php\ext\php_opcache.dll"
opcache.enable=1
Other Configuration of opcache is here https://www.php.net/manual/en/opcache.configuration.php
Also Note that you can configure opcache.enable=1 by only php.ini. if you use ini_set() it will generate error.
Restart you xampp php service and now you can see all configuration by using phpinfo()
and finally you can use
print_r(opcache_get_status());
opcache_get_status() will show you all your opcache statistics, cached file , memory consumption etc.
Upvotes: 1
Reputation: 1304
As far as I know, opcaching is not enabled by default. You can enable it from the php.ini
. You do not need to install anything else, it is pre-built in PHP >=5.5.0.
As for the checking, a simple opcache_get_status()
should do the trick.
I hope this helps. If there is anything unclear, please let me know.
Upvotes: 0