John Davidson

Laravel 9 on PHP 8.1 slow responses - out of the box

0 comments
Message:


I am using out of the box Laravel 9 / php 8.1 combo and loading initial page for 190ms sounds horrible. Last project I built used laravel7 and the response times in development including database queries - talking complex ones were less than 20ms


Currently I am trying to set it up, so the tests were simply loading the default route or just a route returning a string.


I tested several instances



  • Custom docker container I've built (amazonlinux, php81, php81-fpm / nginx ) on an old server

  • Local Windows 10 instance / php81 / artisan serve

  • Pre-built container by bitnami


All of them showed responses ranging from 80ms to 2200ms




  • My custom container because of the optimizations showed responses of 60ms - 80ms, but on the 3rd-4th refresh it pulled a 450-900ms response time

  • On Windows 10 instance there was stable response, but horribly slow ~85-130ms

  • Pre-built container was also stable on around 190ms


You can understand the horror as those are simply empty frameworks deployed.


My test case where a database from another container was pulled to select 1-100 records didn't change the response times. Database was pulled in less than 10ms.


For comparison, because I started reviewing php-fpm configuration (still out of the box on all test cases) I ran some benchmarks if this is the bottleneck, but it was performing flawless. Ops/sec were as described on normal php8.1 benchmarks


Strange thing I've noticed was within Xdebug on my custom container, there were 2300 more records below this.




My Answer:
It seems like there may be some underlying issue causing the slow response times in your Laravel 9 application on PHP 8.1. Here are a few things you can try to troubleshoot and improve the performance:

1. Check your Laravel application configuration: Make sure that your Laravel application is properly configured and optimized for performance. Check your configuration files, caching settings, and any third-party packages that may be affecting performance.

2. Optimize your database queries: Make sure that your database queries are optimized and efficient. Use Laravel's query builder or Eloquent ORM to streamline your database interactions and reduce query times.

3. Enable caching: Utilize Laravel's caching mechanisms to store and retrieve data more efficiently. Consider using caching for frequently accessed data to reduce the load on your database.

4. Check your server environment: Make sure that your server environment is properly configured for optimal performance. Check your PHP-FPM settings, server resources, and any other configurations that may impact performance.

5. Monitor and analyze performance: Use tools like New Relic, Blackfire, or Xdebug to monitor and analyze the performance of your application. Identify any bottlenecks or slow-performing components that may be causing the slow response times.

6. Consider upgrading to the latest version of Laravel: Laravel 9 may have performance improvements and optimizations that could help improve response times. Consider upgrading to the latest version to see if it resolves the issue.

By following these steps and investigating the potential causes of the slow response times, you should be able to identify and address the performance issues in your Laravel 9 application on PHP 8.1.

Rate this post

5 of 5 based on 5237 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us