3

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-

  1. 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.

  2. Does PHP uses OPCODE caching by default or we have to enable it by installing any external library?

2
  • Opcache can actually significantly increase response time. You can enable or disable this in your php.ini file. Commented Aug 5, 2019 at 10:20
  • Another way to see the settings of the OPcache is to use phpinfo(). It shows mine is enabled, and has 647 scripts cached. Commented Aug 5, 2019 at 10:28

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.