Laravel applications often contain a large number of files that need to be interpreted with each server request. In my project, the number of files reached 20,000, causing significant disk load and affecting page load speed. The solution to this problem was using PHP OPcache, which significantly reduced IOPS and doubled the speed of request processing.
The simplest way to measure the time required to load the web resource is by using the following command:
$ time curl -Vk https://web.resource.com/
To enable OPcache, you need to install or ensure that the OPcache extension is already available in PHP.
For Debian/Ubuntu, run:
$ sudo apt install php-opcache
Check if OPcache is active:
$ php -m | grep opcache
If opcache is not enabled, add or modify php.ini:
zend_extension=opcache.so opcache.enable=1 opcache.memory_consumption=128 opcache.max_accelerated_files=20000 opcache.validate_timestamps=0
To apply the changes, restart your web server:
$ sudo systemctl restart apache2 # For Apache $ sudo systemctl restart nginx # For Nginx $ sudo systemctl restart php-fpm # If using PHP-FPM
After enabling OPcache, the performance of the Laravel application doubled due to the following improvements:
If your Laravel application contains a large number of files, enabling OPcache is one of the simplest and most effective ways to improve performance. This solution allowed us to cut page load times in half, significantly enhancing the user experience and reducing server load.