This is a very often asked question among PHP developers. This gist aims to answer it.
- Done in DigitalOcean, cheapest droplet ($5), located in Singapore, using Ubuntu Server 18.04.3. (Referral link for anybody interested.)
- System configured with (mostly) default configuration, using what's available from the package installation.
- PHP versions used are the latest version of 7.1, 7.2 and 7.2 as of October 11th 2019, with both CLI and Nginx FPM version being used.
- Code used in bechmark is down below.
Using help from ppa:ondrej/nginx
and ppa:ondrej/php
:
$ sudo add-apt-repository -y ppa:ondrej/nginx
$ sudo add-apt-repository -y ppa:ondrej/php
$ sudo apti install -y nginx php7.3-fpm php7.3-cli php7.3-curl \
php7.2-fpm php7.2-cli php7.2-curl php7.1-fpm php7.1-cli php7.1-curl
Is also down below, in JSON format, done by microtime()
.
Spoiler!
file_get_contents()
is slightly faster than cURL. As it doesn't need any dependency (cURL needs php-curl
extension), that's a big win for me.