What is Laravel?
Laravel is now widely recognised as the number one PHP framework for web applications. Its open source nature and popularity amongst the development community means that all manner of businesses have chosen Laravel for one of more of their systems, from startups, to software development agencies, to large corporates such as the BBC and Crowdcube.
Why is optimisation important?
As systems grow in numbers of users, amount of stored data and complexity, it is possible that performance bottlenecks can creep into a system. Users of business-critical systems will need them to be fast and reliable to avoid having an impact on business performance. Luckily there are several very simple steps that Laravel developers can take to significantly reduce the server overhead of applications and therefore improve their speed and reliability.
It’s always advised to be as up-to-date with your development frameworks as possible, therefore it’s recommended your application environment is at least:
- PHP 7.1.3
- Laravel 5.7
To check your current Laravel version, at the command line, enter:
php artisan --version
If you’re not up to date we’ll be posting our upgrade guide in due course.
Three simple steps for improving performance
1. Cache your config
This means Laravel is not reading the application configuration from the config files on every load, and can provide a noticeable performance boost. To enable this, at the command line enter:
php artisan config:cache
Don’t forget to re-run this if you make any changes to configuration files. If you need to clear the cache and disable this feature, enter:
php artisan config:clear
2. Cache your web routes
Applications with a number of pages/routes can benefit from caching the route files, similar to above, to enable this, enter:
php artisan route:cache
Don’t forget to re-run this if you make any changes to route files. If you need to clear the cache and disable this feature, enter:
php artisan route:clear
3. Cache API routes
Most applications will have some level of API functionality. Depending on your approach to building your API, there may be options for specifically caching API routes. If using the Dingo API package for example, running the following command will cache your application’s API routes:
php artisan api:cache
Don’t forget to re-run this if you make any changes to API route files. If you need to clear the cache and disable this feature, enter:
php artisan api:clear
1. Cache sessions and queries
Queries can be cached using a suitable cache driver, the key options being a database cache driver, Memcached or Redis. Going into details will require another article which will be coming in due course but the Laravel Docs provide a great primer.
2. Separate application and database servers
This again would require a separate article to explain in detail but by separating the application logic files from the database will significantly reduce the server load for each, improving application response times.
We hope this helps if you want to take a proactive approach to improving your application’s performance.
We’re big fans of Laravel here at Welcm, but we’re even bigger fans of businesses using fast, reliable software to help them perform at their best. If you have applications in your business that are old, no longer supported, or are struggling with performance then get in touch to find out how we can help.
Like this story? Please follow us on Twitter.
At Welcm we design, develop and support touch screen applications and systems.
We also make Visitor Management Easy at https://welcm.ly