r/PHPhelp • u/tc712bb • Apr 30 '26
PHP-FPM vs PHP-CLI
I'm running some simple PHP 8.5 tests (empty loop, open database connection, ...) on a MacBook Pro with Debian in a UTM VM.
With exactly the same code fragment, CPU usage is always 2–3 times higher with PHP-FPM than with PHP-CLI.
Is this normal? Or does it have to do with my settings?
4
Upvotes
10
u/LordAmras Apr 30 '26
CLI and FPM doe 2 different things and work in different ways, so different CPU usages are expected.
But if you feels that the CPU of FPM is too high, you can check the settings. Classic cause can be an high number of max-children on few available cores.
6
u/maskapony Apr 30 '26
You'd have to share your settings, fpm manages multiple processes whereas your cli script will just be a single one.
If you use the default fpm settings then it will be keeping additional processes loaded and warm so they can quickly jump in and serve multiple requests at the same time.
Additionally the settings and modules loaded for cli and fpm are completely separate so there could be a massive difference in overhead because of that.
1
u/latiriti Apr 30 '26
PHP-FPM and PHP-CLI are different SAPIs (Server APIs) with different operating modes. CLI is optimized for one-off tasks and does not recreate the environment for every request, while FPM spawns worker processes, handles HTTP requests, and also has overhead from the FastCGI protocol itself.
1
u/MartinMystikJonas May 01 '26
Do you run both as same uset? If you run CLI as root and FPM as www-data (default) it can be caused by kernel level permission checks.
3
u/obstreperous_troll Apr 30 '26
Check the FPM log file and make sure it's not restarting in a tight loop. If it is, and you figure out how to fix it, let me know. For me it happened in a particular dev setup, but not production, so I just moved off FPM in dev.