Mysql connection problems, there are too many!
So I am running a site with decent traffic, not sure how many, but maybe 100 - 200 users, possibly up to 1000. I am connecting to a remote mysql database with a limit of 1400 connections.
I configured php-fpm to this:
>pm = dynamic
pm.max_children = 200
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 190
pm.max_spawn_rate = 32
When running ps -ef | grep php-fpm I got 31 processes. Somehow through, they generate more than 1400 mysql connections! I set PDO::ATTR_PERSISTENT => true to the PDO instance:
$db = new PDO('mysql:host=' . DBHOST .
';dbname=' . DBNAME . ';charset=UTF8', DBUSER, DBPASS,
PDO::ATTR_PERSISTENT => true
);
$db->setAttribute(PDO::ATTRERRMODE, PDO::ERRMODEEXCEPTION);
$db = new PDO('mysql:host=' . DBHOST .
';dbname=' . DBNAME . ';charset=UTF8', DBUSER, DBPASS,
PDO::ATTR_PERSISTENT => true
);
$db->setAttribute(PDO::ATTRERRMODE, PDO::ERRMODEEXCEPTION);
I also have an Illuminate capsule instance called by this noscript:
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
<?php
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
requireonce 'vendor/autoload.php';
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => DBHOST,
'database' => DBNAME,
'username' => DBUSER,
'password' => DBPASS,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4unicodeci',
'prefix' => '',
'options' => [
PDO::ATTRPERSISTENT => true // Enable persistent connections
]
]);
// Set the event dispatcher used by Eloquent models... (optional)
$capsule->setEventDispatcher(new Dispatcher(new Container));
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
<?php
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
requireonce 'vendor/autoload.php';
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => DBHOST,
'database' => DBNAME,
'username' => DBUSER,
'password' => DBPASS,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4unicodeci',
'prefix' => '',
'options' => [
PDO::ATTRPERSISTENT => true // Enable persistent connections
]
]);
// Set the event dispatcher used by Eloquent models... (optional)
$capsule->setEventDispatcher(new Dispatcher(new Container));
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
Essentially, I run this noscript every time I access a PHP noscript. So I have two connections, one "raw" PDO and one Illuminate Capsule. What might be the problem?
I am trying to think of how to solve this, I need to throttle the connections. Implement a pool or something. I am quite limited on options since my server only have 2GB ram.
https://redd.it/1nhh9cg
@r_php
So I am running a site with decent traffic, not sure how many, but maybe 100 - 200 users, possibly up to 1000. I am connecting to a remote mysql database with a limit of 1400 connections.
I configured php-fpm to this:
>pm = dynamic
pm.max_children = 200
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 190
pm.max_spawn_rate = 32
When running ps -ef | grep php-fpm I got 31 processes. Somehow through, they generate more than 1400 mysql connections! I set PDO::ATTR_PERSISTENT => true to the PDO instance:
$db = new PDO('mysql:host=' . DBHOST .
';dbname=' . DBNAME . ';charset=UTF8', DBUSER, DBPASS,
PDO::ATTR_PERSISTENT => true
);
$db->setAttribute(PDO::ATTRERRMODE, PDO::ERRMODEEXCEPTION);
$db = new PDO('mysql:host=' . DBHOST .
';dbname=' . DBNAME . ';charset=UTF8', DBUSER, DBPASS,
PDO::ATTR_PERSISTENT => true
);
$db->setAttribute(PDO::ATTRERRMODE, PDO::ERRMODEEXCEPTION);
I also have an Illuminate capsule instance called by this noscript:
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
<?php
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
requireonce 'vendor/autoload.php';
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => DBHOST,
'database' => DBNAME,
'username' => DBUSER,
'password' => DBPASS,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4unicodeci',
'prefix' => '',
'options' => [
PDO::ATTRPERSISTENT => true // Enable persistent connections
]
]);
// Set the event dispatcher used by Eloquent models... (optional)
$capsule->setEventDispatcher(new Dispatcher(new Container));
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
<?php
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
requireonce 'vendor/autoload.php';
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => DBHOST,
'database' => DBNAME,
'username' => DBUSER,
'password' => DBPASS,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4unicodeci',
'prefix' => '',
'options' => [
PDO::ATTRPERSISTENT => true // Enable persistent connections
]
]);
// Set the event dispatcher used by Eloquent models... (optional)
$capsule->setEventDispatcher(new Dispatcher(new Container));
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
Essentially, I run this noscript every time I access a PHP noscript. So I have two connections, one "raw" PDO and one Illuminate Capsule. What might be the problem?
I am trying to think of how to solve this, I need to throttle the connections. Implement a pool or something. I am quite limited on options since my server only have 2GB ram.
https://redd.it/1nhh9cg
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
SymfonyCon Amsterdam 2025: Coping With a Bad Sequel: SELECT * FROM Regret
https://symfony.com/blog/symfonycon-amsterdam-2025-coping-with-a-bad-sequel-select-from-regret?utm_medium=feed&utm_source=Symfony%20Blog%20Feed
https://redd.it/1nho0bj
@r_php
https://symfony.com/blog/symfonycon-amsterdam-2025-coping-with-a-bad-sequel-select-from-regret?utm_medium=feed&utm_source=Symfony%20Blog%20Feed
https://redd.it/1nho0bj
@r_php
Symfony
SymfonyCon Amsterdam 2025: Coping With a Bad Sequel: SELECT * FROM Regret (Symfony Blog)
🌀 SQL is bending under the weight of modern data. Join Andreas for a whirlwind tour from its tidy-table origins to today’s tangled mix of JSON, documents, and hybrid query languages—and see whe…
I turned FilamentPHP into a no-code app, sort of
Hi,
I want to start by saying that I enjoy using FilamentPHP, have been working with it since v2, on various projects, and now it is my go-to tool when creating anything admin panel-related.
With that being said, you still have to code stuff, so I thought, what if I could make FilamentPHP work as a no-code tool?
So I did that, sort of. Well, I did mostly a demo, you can basically create TextInput, Selects, and define one-to-one and one-to-many relationships.
Now to share some technical details. The whole project runs on SQLite (I was inspired by PocketBase and the idea of having a lightweight, standalone, independent tool that doesn't need any other resources running to use it other than the web server itself). In order to make this thing work alongside Laravel and FilamentPHP I created a GenericModel class to talk with the database, custom migrations for database relationships as well as a somewhat easy-to-extend builder for forms and tables.
The project is of course very early, there is stuff that works on the surface, but if you look behind the scenes is not good code, there is no docs, no way to extend anything other than modifying the core.
Long story short, if you are curious, want to share any feedback, or anything really here is a link to the repo https://github.com/morfibase/morfibase
https://redd.it/1nhq1ap
@r_php
Hi,
I want to start by saying that I enjoy using FilamentPHP, have been working with it since v2, on various projects, and now it is my go-to tool when creating anything admin panel-related.
With that being said, you still have to code stuff, so I thought, what if I could make FilamentPHP work as a no-code tool?
So I did that, sort of. Well, I did mostly a demo, you can basically create TextInput, Selects, and define one-to-one and one-to-many relationships.
Now to share some technical details. The whole project runs on SQLite (I was inspired by PocketBase and the idea of having a lightweight, standalone, independent tool that doesn't need any other resources running to use it other than the web server itself). In order to make this thing work alongside Laravel and FilamentPHP I created a GenericModel class to talk with the database, custom migrations for database relationships as well as a somewhat easy-to-extend builder for forms and tables.
The project is of course very early, there is stuff that works on the surface, but if you look behind the scenes is not good code, there is no docs, no way to extend anything other than modifying the core.
Long story short, if you are curious, want to share any feedback, or anything really here is a link to the repo https://github.com/morfibase/morfibase
https://redd.it/1nhq1ap
@r_php
GitHub
GitHub - morfibase/morfibase
Contribute to morfibase/morfibase development by creating an account on GitHub.
Free Udemy Course: PHP REST API Cybersecurity (Deal Ends Soon)
https://cybersecurityclub.substack.com/p/free-udemy-course-php-rest-api-cybersecurity
https://redd.it/1nhumea
@r_php
https://cybersecurityclub.substack.com/p/free-udemy-course-php-rest-api-cybersecurity
https://redd.it/1nhumea
@r_php
Substack
Free Udemy Course: PHP REST API Cybersecurity (Deal Ends Soon)
If you want to strengthen your skills in securing PHP REST APIs, you can now enroll in this Udemy course at no cost with a limited-time coupon.
PHP (Non Thread Safe) now on WinGet
As I use PHP for general Windows noscripting tasks I was happy to see the (faster) NTS version added to the WinGet package manager only a few days after a post I made to the PHP mailing list. I'm impressed.
https://redd.it/1nies7m
@r_php
As I use PHP for general Windows noscripting tasks I was happy to see the (faster) NTS version added to the WinGet package manager only a few days after a post I made to the PHP mailing list. I'm impressed.
https://redd.it/1nies7m
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
How much AI assistance do you use when working on Laravel projects?
This is something I've been wondering about for a while in the greater Laravel community. For me personally, I tend to only use Copilot inside PHPStorm as mostly a glorified autocomplete when it comes to creating files.
If I'm stuck on a particular method or completing a test assertion, it can come in handy, but I don't let it have free rein over dictating what my code is or should do, as that tends to lead to readability issues and undesired outcomes in my experience.
I imagine there are two camps: no AI or only uses AI and with lots of nuance in between.
How much AI do you use in projects and what do you use? I know AI can be such a hot topic but I'm curious to see what people's thoughts are specifically within the Laravel world.
https://redd.it/1niekdh
@r_php
This is something I've been wondering about for a while in the greater Laravel community. For me personally, I tend to only use Copilot inside PHPStorm as mostly a glorified autocomplete when it comes to creating files.
If I'm stuck on a particular method or completing a test assertion, it can come in handy, but I don't let it have free rein over dictating what my code is or should do, as that tends to lead to readability issues and undesired outcomes in my experience.
I imagine there are two camps: no AI or only uses AI and with lots of nuance in between.
How much AI do you use in projects and what do you use? I know AI can be such a hot topic but I'm curious to see what people's thoughts are specifically within the Laravel world.
https://redd.it/1niekdh
@r_php
Reddit
From the laravel community on Reddit
Explore this post and more from the laravel community
Symfony : Strategy Pattern explained... thanks to Autowire Iterator!
https://youtu.be/9hUIl-dpoFs
https://redd.it/1nihene
@r_php
https://youtu.be/9hUIl-dpoFs
https://redd.it/1nihene
@r_php
YouTube
Symfony : Pattern Strategy expliqué… grâce à l’Autowire Iterator !
Dans cette vidéo, nous explorons l’implémentation du pattern Strategy dans un projet Symfony moderne.
Ce tutoriel s’adresse aux développeurs qui souhaitent améliorer la flexibilité et la maintenabilité de leurs applications Symfony à travers les bonnes pratiques…
Ce tutoriel s’adresse aux développeurs qui souhaitent améliorer la flexibilité et la maintenabilité de leurs applications Symfony à travers les bonnes pratiques…
SymfonyCon Amsterdam 2025: The Double-Edged Sword of Code Quality Tools
https://symfony.com/blog/symfonycon-amsterdam-2025-the-double-edged-sword-of-code-quality-tools?utm_medium=feed&utm_source=Symfony%20Blog%20Feed
https://redd.it/1nimwhx
@r_php
https://symfony.com/blog/symfonycon-amsterdam-2025-the-double-edged-sword-of-code-quality-tools?utm_medium=feed&utm_source=Symfony%20Blog%20Feed
https://redd.it/1nimwhx
@r_php
Symfony
SymfonyCon Amsterdam 2025: The Double-Edged Sword of Code Quality Tools (Symfony Blog)
🧩 Are we the sharpest (quality) tool in the shed? Join Konrad Oboza to explore how relying too much on code quality tools can backfire—and how to strike the right balance for truly effective deve…
whereBetween vs. whereValueBetween vs. whereBetweenColumns ?
https://nabilhassen.com/laravel-wherebetween-vs-wherevaluebetween-vs-wherebetweencolumns
https://redd.it/1nin7nb
@r_php
https://nabilhassen.com/laravel-wherebetween-vs-wherevaluebetween-vs-wherebetweencolumns
https://redd.it/1nin7nb
@r_php
Nabilhassen
Laravel: whereBetween vs whereValueBetween vs whereBetweenColumns
Confused about Laravel’s whereBetween, whereBetweenColumns, and whereValueBetween? Discover their hidden differences with real SQL examples!
PHP Fundamentals [Full Course]
https://youtu.be/EX3qQqdm16I?feature=shared
https://redd.it/1niq0sy
@r_php
https://youtu.be/EX3qQqdm16I?feature=shared
https://redd.it/1niq0sy
@r_php
YouTube
PHP Fundamentals [FULL COURSE]
Learn the essentials of modern PHP in this beginner-friendly course. Whether you're new to PHP or coming from another language, this course provides a solid foundation for PHP development and prepares you for working with Laravel. In 10 concise lessons, we'll…
The NativePHP Mobile Kitchen Sink app is now open source (MIT)
https://nativephp.com/blog/kitchen-sink-unlocked
https://redd.it/1nithda
@r_php
https://nativephp.com/blog/kitchen-sink-unlocked
https://redd.it/1nithda
@r_php
Reddit
From the PHP community on Reddit: The NativePHP Mobile Kitchen Sink app is now open source (MIT)
Posted by simonhamp - 0 votes and 0 comments
Longhorn PHP full schedule
Hey y'all - just wanted to share that the full schedule is now online for this year's Longhorn PHP:
https://longhornphp.com/
The conference is October 23-25 in Austin, TX. We have virtual ($75) and in-person ($250-$350) ticket options.
https://redd.it/1niuz2k
@r_php
Hey y'all - just wanted to share that the full schedule is now online for this year's Longhorn PHP:
https://longhornphp.com/
The conference is October 23-25 in Austin, TX. We have virtual ($75) and in-person ($250-$350) ticket options.
https://redd.it/1niuz2k
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
The NativePHP Mobile Kitchen Sink app is now open source (MIT)
https://nativephp.com/blog/kitchen-sink-unlocked
https://redd.it/1nitgx1
@r_php
https://nativephp.com/blog/kitchen-sink-unlocked
https://redd.it/1nitgx1
@r_php
Reddit
From the laravel community on Reddit: The NativePHP Mobile Kitchen Sink app is now open source (MIT)
Posted by simonhamp - 7 votes and 0 comments
SQL performance improvements: finding the right queries to fix (part 1)
https://ohdear.app/news-and-updates/sql-performance-improvements-finding-the-right-queries-to-fix-part-1
https://redd.it/1nisyf5
@r_php
https://ohdear.app/news-and-updates/sql-performance-improvements-finding-the-right-queries-to-fix-part-1
https://redd.it/1nisyf5
@r_php
ohdear.app
SQL performance improvements: finding the right queries to fix (part 1)
This post covers tips and tricks for performance tweaking your SQL queries by first identifying which queries need work.
SymfonyCon Amsterdam 2025: Testing with(out) dependencies
https://symfony.com/blog/symfonycon-amsterdam-2025-testing-with-out-dependencies?utm_medium=feed&utm_source=Symfony%20Blog%20Feed
https://redd.it/1njfb9u
@r_php
https://symfony.com/blog/symfonycon-amsterdam-2025-testing-with-out-dependencies?utm_medium=feed&utm_source=Symfony%20Blog%20Feed
https://redd.it/1njfb9u
@r_php
Symfony
SymfonyCon Amsterdam 2025: Testing with(out) dependencies (Symfony Blog)
🧪 Master the art of stubs and mocks. Join Sebastian to demystify test doubles in PHPUnit and learn when to fake dependencies—or trust the real ones—for cleaner, more reliable tests.
Existing Laravel app now needs an API
Hey all
I build a Laravel app with Inertia for a client a couple of years back and it's still working perfectly. My client now wants a mobile app as part of the solution which will need to access the data.
So...add an API with JWT to the existing project and make use of services to share code, or create a separate API project accessing the same database or something else?
I'm sure others have faced this issue so interested to hear what swayed the decision.
Cheers.
https://redd.it/1njgct3
@r_php
Hey all
I build a Laravel app with Inertia for a client a couple of years back and it's still working perfectly. My client now wants a mobile app as part of the solution which will need to access the data.
So...add an API with JWT to the existing project and make use of services to share code, or create a separate API project accessing the same database or something else?
I'm sure others have faced this issue so interested to hear what swayed the decision.
Cheers.
https://redd.it/1njgct3
@r_php
Reddit
From the laravel community on Reddit
Explore this post and more from the laravel community
Laravel 12.29: Introducing Session Cache
https://nabilhassen.com/session-cache-in-laravel-1229
https://redd.it/1njiz8h
@r_php
https://nabilhassen.com/session-cache-in-laravel-1229
https://redd.it/1njiz8h
@r_php
Nabilhassen
Session Cache in Laravel 12.29
Laravel 12.29 introduces Session Cache, letting you store user-specific data per session using familiar cache methods, cleared when the session ends.
My own super strict laravel starter kit
https://github.com/nunomaduro/laravel-starter-kit
https://redd.it/1njn93c
@r_php
https://github.com/nunomaduro/laravel-starter-kit
https://redd.it/1njn93c
@r_php
GitHub
GitHub - nunomaduro/laravel-starter-kit: Laravel Starter Kit is an ultra-strict, type-safe Laravel skeleton engineered for developers…
Laravel Starter Kit is an ultra-strict, type-safe Laravel skeleton engineered for developers who refuse to compromise on code quality. - nunomaduro/laravel-starter-kit
Laravel MultiTenant, MultiDatabase (JOBS)
Bom, estou desenvolvendo um cardápio online totalmente em Laravel. A aplicação já estava praticamente pronta, mas tive a ideia de transformá-la em multi-tenant. Grande parte já está funcionando, porém me deparei com um problema.
Tenho um banco principal, que vou chamar de "Principal", e os bancos dos tenants: "Tenant1", "Tenant2", e assim por diante. Estou utilizando filas do Laravel porque também uso WebSocket (Laravel Reverb), além da integração com WhatsApp via Twilio.
Centralizei todos os jobs na tabela do banco Principal, ou seja, todos os jobs de todos os tenants são enfileirados lá. Como a aplicação é um cardápio, ela não precisa ser 100% em tempo real, então esse modelo faz sentido.
O problema é que, quando envio um job para disparar mensagens no WhatsApp, a aplicação não consegue se conectar ao banco do tenant. Esse job chama um service responsável pelo envio.
Alguém aqui já trabalhou com filas em sistema multi-tenant no Laravel e poderia me dar uma luz?
https://redd.it/1njp5nf
@r_php
Bom, estou desenvolvendo um cardápio online totalmente em Laravel. A aplicação já estava praticamente pronta, mas tive a ideia de transformá-la em multi-tenant. Grande parte já está funcionando, porém me deparei com um problema.
Tenho um banco principal, que vou chamar de "Principal", e os bancos dos tenants: "Tenant1", "Tenant2", e assim por diante. Estou utilizando filas do Laravel porque também uso WebSocket (Laravel Reverb), além da integração com WhatsApp via Twilio.
Centralizei todos os jobs na tabela do banco Principal, ou seja, todos os jobs de todos os tenants são enfileirados lá. Como a aplicação é um cardápio, ela não precisa ser 100% em tempo real, então esse modelo faz sentido.
O problema é que, quando envio um job para disparar mensagens no WhatsApp, a aplicação não consegue se conectar ao banco do tenant. Esse job chama um service responsável pelo envio.
Alguém aqui já trabalhou com filas em sistema multi-tenant no Laravel e poderia me dar uma luz?
https://redd.it/1njp5nf
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community