Skip to content

Commit

Permalink
Merge pull request #41 from myaaghubi/v2.2
Browse files Browse the repository at this point in the history
V2.2
  • Loading branch information
myaaghubi authored Aug 2, 2023
2 parents e710ff7 + 9836910 commit f0065cc
Show file tree
Hide file tree
Showing 87 changed files with 152 additions and 243 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test PHP benchmark
on: [ push, pull_request ]

jobs:
setup:
name: Check PHP frameworks
runs-on: ubuntu-22.04

steps:

- uses: actions/checkout@v3

- name: Install WRK
run: sudo apt-get install wrk w3m

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: dom, curl, libxml, mbstring, zip, pcntl, ctype, iconv, intl
coverage: none

- name: Install Apache mod_php
run: |
LC_ALL=C.UTF-8 sudo apt-add-repository http://ppa.launchpad.net/ondrej/php/ubuntu
sudo apt install libapache2-mod-php8.2
sudo a2enmod php8.2 rewrite
shell: bash

- name: Setup frameworks
run: bash setup.sh

- name: Copy files to web root
run: |
sudo mkdir /var/www/html/PHP-Frameworks-Bench
sudo cp -R ./* /var/www/html/PHP-Frameworks-Bench/
sudo chown -R www-data:www-data /var/www/html
- name: Restart apache server
run: sudo service apache2 restart

- name: Check frameworks
run: bash check.sh

5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/output/
vendor/
#/*/code/
/output/*
vendor/
1 change: 1 addition & 0 deletions 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.2.8
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# PHP Frameworks Bench
![GitHub release (latest by date)](https://img.shields.io/github/v/release/myaaghubi/PHP-Frameworks-Bench?color=purpol) ![GitHub](https://img.shields.io/github/license/myaaghubi/PHP-Frameworks-Bench?color=green)
[![Test PHP benchmark](https://github.com/myaaghubi/PHP-Frameworks-Bench/actions/workflows/test.yml/badge.svg)](https://github.com/myaaghubi/PHP-Frameworks-Bench/actions/workflows/test.yml) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/myaaghubi/PHP-Frameworks-Bench?color=purpol) ![GitHub](https://img.shields.io/github/license/myaaghubi/PHP-Frameworks-Bench?color=green)

This project attempts to measure the minimum overhead (minimum bootstrap cost) of PHP frameworks in the real world.

Expand Down Expand Up @@ -56,18 +56,16 @@ These are my benchmarks, not yours. **I encourage you to run on your (production
|phroute-2.2 | 4,303.07| 44.4| 0.58| 1.4|
|leaf-3.3 | 1,576.68| 16.3| 1.10| 2.6|
|fatfree-3.8.1 | 1,512.30| 15.6| 1.67| 4.0|
|siler-1.7.9 | 1,416.80| 14.6| 1.17| 2.8|
|slim-3.12 | 1,061.05| 10.9| 1.40| 3.3|
|slim-4.11 | 805.51| 8.3| 1.57| 3.7|
|ubiquity-2.4.x.dev | 726.70| 7.5| 1.64| 3.9|
|silex-2.3 | 558.07| 5.8| 2.16| 5.1|
|yii-2.0-basic | 508.32| 5.2| 2.57| 6.1|
|fuelphp-1.9 | 450.65| 4.6| 2.51| 6.0|
|lumen-10.0 | 352.94| 3.6| 3.49| 8.3|
|codeigniter-4.3 | 324.27| 3.3| 3.50| 8.3|
|symfony-5.4 | 319.55| 3.3| 3.82| 9.1|
|symfony-6.2 | 314.21| 3.2| 3.89| 9.2|
|symfony-5.4 | 311.74| 3.2| 3.82| 9.1|
|laminas-2.0 | 309.30| 3.2| 3.50| 8.3|
|symfony-6.3 | 290.69| 3.0| 3.91| 9.3|
|cakephp-4.4 | 262.25| 2.7| 4.49| 10.7|
|laravel-10.0 | 96.97| 1.0| 11.99| 28.5|

Expand Down Expand Up @@ -181,15 +179,13 @@ For frameworks, I considered the official repos:
* [CodeIgniter](https://github.com/codeigniter4/CodeIgniter4)
* [FastRoute](https://github.com/nikic/FastRoute)
* [FatFree](https://github.com/bcosca/fatfree)
* [FrameworkX](https://github.com/clue/framework-x)
* [FuelPHP](https://github.com/fuelphp/fuelphp)
* [KumbiaPHP](https://github.com/KumbiaPHP/KumbiaPHP)
* [Laminas](https://github.com/laminas)
* [Laravel](https://github.com/laravel/laravel)
* [Leaf](https://github.com/leafsphp/leaf)
* [Lumen](https://github.com/laravel/lumen)
* [PhRoute](https://github.com/mrjgreen/phroute)
* [Siler](https://github.com/leocavalcante/siler)
* [Silex](https://github.com/silexphp/Silex)
* [Slim](https://github.com/slimphp/Slim)
* [Symfony](https://github.com/symfony/symfony)
Expand Down
4 changes: 1 addition & 3 deletions base/_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ benchmark () {
url_status=$(bash check.sh -t "$fw")

# find 'done'
status=${url_status%%done*}
status=${url_status%%${fw}*}

# if the index of 'done' be equal to
# the length of the url_status then
Expand Down Expand Up @@ -90,6 +90,4 @@ benchmark () {
fi

echo "$url" >> "$url_file"

echo
}
13 changes: 7 additions & 6 deletions base/hello_world.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ if [ -f "$url_file" ]; then
mv "$url_file" "$url_file.old"
fi


phpv=`php -r 'echo phpversion();'`
echo "/------- PHP $phpv -------/"
phpc=`curl -s "$base/libs/php_config.php"`
echo "/------- PHP Config -------/"
echo "$phpc"

for fw in `echo $param_targets`
do
if [ -d "$fw" ]; then
echo "/------- $fw -------/"
echo "\n/------- $fw -------/"

# read -p "Continue to $fw (y/n)?" choice
# case "$choice" in
Expand All @@ -54,7 +54,7 @@ do

if [ "$param_clean" = true ]; then
bash clean.sh
bash setup.sh "$fw"
bash setup.sh -t "$fw"
fi

# read -p "Continue to benchmark (y/n)?" choice
Expand All @@ -67,7 +67,8 @@ do
# fi

# reset the opcache
php ./libs/reset_opcache.php
opcacherest=`curl -s "$base/libs/reset_opcache.php"`
echo "$opcacherest"

if [ "$param_restart_apache" = true ]; then
echo 'systemctl restart apache2'
Expand Down
9 changes: 3 additions & 6 deletions benchmark.config
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,18 @@ cakephp-4.4
codeigniter-4.3
fastroute-1.3
fatfree-3.8.1
frameworkx-dev
fuelphp-1.9
kumbiaphp-1.1
kumbia-1.1
laminas-2.0
laravel-10.0
leaf-3.3
lumen-10.0
phroute-2.2
pure-php
siler-1.7.9
silex-2.3
slim-3.12
slim-4.11
symfony-5.4
symfony-6.2
symfony-6.3
ubiquity-2.4.x.dev
yii-2.0-basic
"
"
1 change: 1 addition & 0 deletions benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ done

sh ./base/hello_world.sh

echo ''
php ./libs/show_results_table.php
26 changes: 21 additions & 5 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,36 @@
. ./benchmark.config
. ./base/option_target.sh

# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

FAIL=0

for fw in `echo $param_targets`
do
if [ -d "$fw" ]; then
echo -n "/------- $fw: checking... "
. "$fw/_benchmark/hello_world.sh"

url_output=$(curl -s "$url")

# expected to get the Hello World! + libs/output_data.php
if ! [[ "$url_output" =~ ^('Hello World!')(.*)(([0-9]*):(([0-9]+([.][0-9]*)?|[.][0-9]+)):([0-9]*))$ ]]; then
echo -e "error: \n$url"
echo "$url_output"
echo -e "${RED}$fw ${NC}"
echo "$url"

if [ -x "$(command -v w3m)" ]; then
echo "$url_output" | w3m -dump -T text/html
else
echo "$url_output"
fi

FAIL=1
else
echo "done."
printf "%-34b %4s bytes %s\n" "${GREEN}$fw ${NC}" "${#url_output}" "$url"
fi
fi
done
done

exit $FAIL
2 changes: 1 addition & 1 deletion codeigniter-4.3/_benchmark/clear-cache.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
# clear cache
sudo rm -rf writable/cache/*
rm -rf writable/cache/*
echo -e "done"
2 changes: 1 addition & 1 deletion codeigniter-4.3/_benchmark/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ yes|cp -r _benchmark/codeigniter/* ./

# some enhancements
composer install --no-dev -o
sudo chown -Rv www-data writable
chmod -R o+w writable
rm ./public/.htaccess
2 changes: 1 addition & 1 deletion codeigniter-4.3/_benchmark/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ yes|cp -r _benchmark/codeigniter/* ./

# some enhancements
composer install --no-dev -o
sudo chown -Rv www-data writable
chmod -R o+w writable
rm ./public/.htaccess
2 changes: 1 addition & 1 deletion fastroute-1.3/_benchmark/clean.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
rm -rf !("_benchmark"|"Controllers"|"composer.json"|"index.php")
rm -rf !("_benchmark"|"Controllers"|"composer.json"|"public")
find -path './.*' -delete
2 changes: 1 addition & 1 deletion fastroute-1.3/_benchmark/hello_world.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
url="$base/$fw/index.php/hello/index"
url="$base/$fw/public/index.php/hello/index"
4 changes: 2 additions & 2 deletions fastroute-1.3/index.php → fastroute-1.3/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// https://github.com/nikic/FastRoute#usage
// Here's a basic usage example:

require __DIR__.'/vendor/autoload.php';
require __DIR__.'/../vendor/autoload.php';


$dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) {
Expand All @@ -22,7 +22,7 @@

// https://github.com/nikic/FastRoute/issues/110#issuecomment-273760186
// Strip prefix
$prefix = '/PHP-Frameworks-Bench/fastroute-1.3';
$prefix = '/PHP-Frameworks-Bench/fastroute-1.3/public';
if ($prefix !== '' && strpos($uri, $prefix) === 0) {
$uri = substr($uri, strlen($prefix));
}
Expand Down
2 changes: 1 addition & 1 deletion fatfree-3.8.1/_benchmark/clean.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
rm -rf !("_benchmark"|"Controllers"|"composer.json"|"index.php")
rm -rf !("_benchmark"|"Controllers"|"composer.json"|"public")
find -path './.*' -delete
2 changes: 1 addition & 1 deletion fatfree-3.8.1/_benchmark/hello_world.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
url="$base/$fw/index.php/hello/index"
url="$base/$fw/public/index.php/hello/index"
2 changes: 1 addition & 1 deletion fatfree-3.8.1/index.php → fatfree-3.8.1/public/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require 'vendor/autoload.php';
require '../vendor/autoload.php';

$f3 = \Base::instance();

Expand Down
14 changes: 0 additions & 14 deletions frameworkx-dev/Controllers/HelloWorldController.php

This file was deleted.

3 changes: 0 additions & 3 deletions frameworkx-dev/_benchmark/clean.sh

This file was deleted.

2 changes: 0 additions & 2 deletions frameworkx-dev/_benchmark/setup.sh

This file was deleted.

2 changes: 0 additions & 2 deletions frameworkx-dev/_benchmark/update.sh

This file was deleted.

10 changes: 0 additions & 10 deletions frameworkx-dev/composer.json

This file was deleted.

22 changes: 0 additions & 22 deletions frameworkx-dev/public/index.php

This file was deleted.

Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions kumbiaphp-1.1/_benchmark/clear-cache.sh

This file was deleted.

2 changes: 1 addition & 1 deletion laminas-2.0/_benchmark/clear-cache.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
# clear cache
sudo rm -rf data/cache/*
rm -rf data/cache/*
echo -e "done"
1 change: 1 addition & 0 deletions laminas-2.0/_benchmark/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ yes|cp -rf _benchmark/laminas/. ./

# some enhancements
composer install --optimize-autoloader --no-dev
chmod -R o+w data/cache
rm ./public/.htaccess
1 change: 1 addition & 0 deletions laminas-2.0/_benchmark/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ yes|cp -rf _benchmark/laminas/. ./

# some enhancements
composer install --optimize-autoloader --no-dev
chmod -R o+w data/cache
rm ./public/.htaccess
Loading

0 comments on commit f0065cc

Please sign in to comment.