I did some simple test: reading csv file with 100 000 rows (10 columns) filled up by random English words. Script opened file, and put every rows to an array variable.
ab -n 100 -l http://localhost:8000
I sent 100 request by Apache Benchmark command to measure how much PHP8.2 is faster than PHP7.4, but... result surprised me. PHP7 was faster with score 66,9 seconds. For PHP8 it tooks 71 seconds. I did tests few times, same result. Why?
Tasks for both PHP versions were ran on indentical environment: Docker, Ubuntu 20.02, default PHP configuration.
In previous tests about calculating prime numbers, PHP8 was much faster. PHP8 is promoted as the fastest version from all of them.
Source code below:
<?php
if (!isset($_GET['phpinfo'])) {
$csvData = [];
if (($handle = fopen("test.csv", "r")) !== FALSE) {
$row = 0;
while (($data = fgetcsv($handle)) !== FALSE) {
$csvData[] = $data;
$row++;
}
fclose($handle);
if ($row === 100000) {
http_response_code(200);
} else {
http_response_code(400);
}
}
} else {
phpinfo();
}
Dockerfile (same for PHP8 - with replaced php version to 8.2 and workdir)
FROM ubuntu:20.04
ARG PHP_VERSION="7.4"
RUN apt update && \
apt -y install --no-install-recommends && \
apt -y install software-properties-common && \
add-apt-repository ppa:ondrej/php && \
apt update && \
apt -y install --no-install-recommends && \
apt -y install php${PHP_VERSION}
WORKDIR /var/www/html/php7
COPY . /var/www/html/php7
docker-compose.yml (same for PHP8 - with replaced php7 to php8)
version: "3.9"
services:
php7:
container_name: php7
build: ./php7
ports:
- "8000:8000"
volumes:
- ./php7:/var/www/html/php7
stdin_open: true
tty: true
restart: always
command: php -S 0.0.0.0:8000 -t .
test.csv (rows like below)
"sides","opportunity","thin","remove","mud","this","appearance","proud","bad","round"