I noticed that a file browser widget was taking considerably longer to load after moving from php 7.2 to 7.3.
An operation that normally takes under a second was taking considerably longer. After enabling slowlog I traced the issue to MIME lookups using finfo. After reverting to 7.2 the issue was resolved.
This is a simple test I created to illustrate the problem:
#!/bin/bash
set -e
ITERS=${1:-1000}
echo "Testing finfo over $ITERS iterations"
for VER in '7.2' '7.3'; do
echo ---
echo "Testing PHP $VER"
docker run -i \
-e "ITERS=${ITERS}" \
php:${VER}-cli-alpine php <<'EOF'
<?php
$iters = $_ENV["ITERS"];
$start = microtime(true);
for ($i = 1; $i <= $iters; $i++){
$finfo = new finfo(FILEINFO_MIME);
$type = $finfo->file("/bin/sh");
unset($finfo);
}
$ttl = microtime(true) - $start;
echo "Took: $ttl\n";
?>
EOF
done
Here is the result as run on a prestine DigitalOcean droplet with 3 CPUs:
root@phptest:~# ./test.sh 1000
Testing finfo over 1000 iterations
---
Testing PHP 7.2
Took: 1.2104759216309
---
Testing PHP 7.3
Took: 2.4543979167938
The 7.3 test took more than twice as long. I've run this test on a number of systems, and in all cases I see an increase in runtime for 7.3 of 30% or more; in some cases far more. This is the same test run on a droplet with more load and only 2 CPUs (this is the machine where I first encountered the problem; which you can see why):
% ./test.sh 100
Testing finfo over 100 iterations
---
Testing PHP 7.2
Took: 0.10123181343079
---
Testing PHP 7.3
Took: 34.721122980118
What could be the cause of this slowdown, and are there any configuration/optimizations that I should be employing?