Celebrate Our 22nd Anniversary with Huge Savings! Up to 70% Off

How to update the value for the following parameters in Linux? opcache.max_accelerated_files opcache.revalidate_freq

What is Opcache.max_accelerated_files?

Opcache.max_accelerated_files is a setting in PHP that controls how many PHP files can be stored in memory for faster execution.

When PHP runs a script, it first needs to translate the code into a form that can be understood quickly, called bytecode. This translation process takes time. OPCache helps by storing this translated code in memory so that PHP doesn't need to do it every time the script runs.

Opcache.max_accelerated_files specifies the maximum number of PHP files that can be kept in this memory cache. Having more files cached means PHP doesn't have to translate them as often, leading to faster performance.

However, increasing this limit uses more memory, so it's a trade-off between speed and memory usage.

 

What is Opcache.revalidate_freq?

Opcache.revalidate_freq is a setting in PHP that determines how often PHP checks if the files it has cached have been modified.

When PHP runs a script, it often stores a copy of its code in memory to speed up future executions. However, if the original script file changes (for example, if you edit the script), PHP needs to update its cached copy to reflect those changes.

Opcache.revalidate_freq specifies how frequently PHP should check if the cached files need to be updated. If you set it to 60 seconds, PHP will check every 60 seconds to see if any of the cached files have been modified.

This setting is useful because it helps balance performance and accuracy. Setting a longer revalidation frequency can improve performance by reducing the number of checks PHP needs to perform, but it might mean that PHP continues to use outdated file versions for longer periods. Conversely, setting a shorter frequency ensures that PHP quickly picks up file changes but might lead to more frequent performance overhead.

 

How to update the value Opcache.revalidate_freq and Opcache.max_accelerated_files in Linux?

To change the settings for opcache.max_accelerated_files and opcache.revalidate_freq in PHP's OPCache on a Linux system, follow these steps:

Step 1: Find your PHP configuration file.

It might be located in /etc/php.ini, /etc/php/php.ini, or another directory like /etc/php/7.x/apache2/php.ini for Apache. Use "php --ini" in the terminal to locate it.

 

 

Step 2: Edit php.ini.

Open the file in a text editor with root privileges, for example:

 

# vi /etc/php.ini

 

Step 3: Locate the settings.

Search for "opcache.max_accelerated_files" and "opcache.revalidate_freq" in the file. If they're not there, add them under the OPCache section.

Step 4: Update the values.

Change the values to your preferred limits, like:

 

opcache.max_accelerated_files = 10000

opcache.revalidate_freq = 60

 

 

Step 5: Save and close the file.

Step 6: Restart the web server:

Use the appropriate command to restart the web server, such as:

 

# systemctl restart apache2 [For Apache Server]

 

 

Step 7: Verify the changes.

Finally, you can confirm that the settings have been updated by creating a simple PHP file that contains "phpinfo()" and opening it in a web browser. Look for "opcache.max_accelerated_files" and "opcache.revalidate_freq" to see the new values.

 

 

Following these steps, you can successfully adjust the performance settings of PHP's OPCache on a Linux system..

 

Conclusion

In conclusion, updating the values of opcache.revalidate_freq and opcache.max_accelerated_files in PHP's OPCache on Linux involves modifying the PHP configuration file (php.ini). Adjusting opcache.revalidate_freq controls how often PHP checks for file modifications, balancing between performance and accuracy.

Meanwhile, changing opcache.max_accelerated_files sets the maximum number of PHP files stored in memory, enhancing execution speed while considering available resources. These adjustments require editing php.ini, restarting the web server, and verifying changes through phpinfo().


Was this answer helpful?

« Back

chat