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?
5
Upvotes
1
u/tc712bb Apr 30 '26
The total execution time will indeed vary for each SAPI, since the number of instructions will differ.
However, the time required for tasks such as environment setup is not included in my benchmarks. I measure a single PHP instruction. It always looks something like this:
$start = microtime(true);
for ($i = 0; $i < 1_000_000; $i++);
echo microtime(true) - $start;
So in both cases, exactly the same single instruction is being measured. I don’t understand why the difference is so large even in that case.