2
7 Comments

Need suggestion or workaround

Hey developers, I'm using Laravel & MySQL in one of my client's project. It is going successful and user engaging. But recently customers are facing some problems like slow data loading, connection refused, server crashed and etc.

Now, can you guys suggest me better option for the fast data loading, data caching, no connection refused?

on March 16, 2021
  1. 2

    Can't really offer much specific help without a lot more details. About the app, usage and how it is currently being hosted. For an immediate work around, add more metal, ie upgrade the server, more RAM, CPU etc.

    Likely has nothing to do with the fact that you're using Laravel.

    I've built and deployed sites on Laravel that serve millions of pageviews per day, but like with any framework, for this kind of scale you need to know what bottlenecks to look out for.

    The biggest problems are usually at the database layer, either with how the information is stored or the queries that information is pulled out of the database with.

    The only other thing to look for is if you're being attacked. This has happened to me a number of times after launching sites, you get targeted, for no apparent reasons other than they can, they even offered to stop once if we paid them.

    In this case you need to get proactive about banning IPs and blocking back actors that are wasting resources.

  2. 2

    Maybe @mubashariqbal can say a word or two about Laravel

  3. 1

    Do you have the MySQL slow query log set up? That might help to point you in the right direction.

  4. 1

    If you aren't caching data already, you should. Use redis to cache data in memory rather than making database queries with every page load. It's easy to implement and will drastically cut down database load.

    Secondly, if you aren't already, I would use cloudflare. Their CDN will speed up loading of images etc; by a large margin and save you a lot of bandwidth. We save around 20TB /mo.

    If you are being attacked (as someone said above) you'll also be able to make use of their "under attack mode" which will help mitigate that.

  5. 1

    if you're on a cloud provider, try to pay for more hardware -- i.e. upgrade plans from 'x' to '2x' or '3x' -- more CPU, Memory, etc.

    if running out of database connections, try to increase the size of the connection pool, assuming you're using one. i don't see any docs about php/laravel connection pools -- strange.

    ...adding, i guess there is really no such thing as 'connection pools' in PHP-land, but there is the concept of 'persistent connections', which is not used by Laravel by default, but can presumably be configured by adding the option to your database configuration.

    but from reading, sounds like you might just need to increase the default MySQL 'max_connections' from 151 to 300 or whatever is required.

    read some stuff about MySQL connections potentially being limited per connecting-host/client or per user, so there might be other MySQL limits you need to adjust.

    you could also make sure you are using some type of caching.

  6. 1

    Hi - can you describe the hosting environment, deployment methodology, and the exact errors they're receiving?