Skip to content

Commit c584dbb

Browse files
authored
Merge pull request #43 from myaaghubi/dev
Dev
2 parents 44f6aa7 + 49d94a7 commit c584dbb

File tree

111 files changed

+8840
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+8840
-150
lines changed

.docker/apache.dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM php:8.2-apache
2+
3+
RUN apt-get update \
4+
&& apt-get install -y libicu-dev
5+
6+
RUN mkdir /var/www/html/PHP-Frameworks-Bench
7+
8+
# Need it in a lot of frameworks
9+
RUN docker-php-ext-install intl
10+
11+
# Optional opcache (recommended)
12+
#RUN docker-php-ext-install opcache
13+
14+
ENV PORT 80
15+
ENTRYPOINT []
16+
CMD sed -i "s/80/$PORT/g" /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf && docker-php-entrypoint apache2-foreground

README.md

Lines changed: 69 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# PHP Frameworks Bench
22
[![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)
33

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

67
So I think the minimum should not include:
@@ -16,9 +17,11 @@ Benchmarking on components like template engines or ORM/Database libraries is ou
1617
- [Benchmarks](#benchmarks)
1718
- [Latest](#latest)
1819
- [OPCache On/Off](#opcache-on)
19-
- [Benchmarking Policy](#benchmarking-policy)
2020
- [How to Benchmark](#how-to-benchmark)
21+
- [Docker](#docker)
2122
- [Commands](#commands)
23+
- [Benchmarking Policy](#benchmarking-policy)
24+
- [Add Your Framework](#add-your-framework)
2225
- [Donate](#-donate)
2326
- [References](#references)
2427
- [License](#license)
@@ -41,12 +44,12 @@ Benchmarking on components like template engines or ORM/Database libraries is ou
4144

4245
#### Results (2023/5/15)
4346

44-
These are my benchmarks, not yours. **I encourage you to run on your (production equivalent) environments.**
47+
These are my benchmarks, not yours. **I encourage you to run on your -production equivalent- environments.**
4548

46-
![Benchmark Results Graph Throughput](screenshots/php-frameworks-bench-throughput.png)
47-
![Benchmark Results Graph Memory](screenshots/php-frameworks-bench-memory.png)
48-
![Benchmark Results Graph Execution Time](screenshots/php-frameworks-bench-exectime.png)
49-
![Benchmark Results Graph Included Files](screenshots/php-frameworks-bench-includedfiles.png)
49+
![Frameworks Benchmark Results Graph Throughput](screenshots/php-frameworks-bench-throughput.png)
50+
![Frameworks Benchmark Results Graph Memory](screenshots/php-frameworks-bench-memory.png)
51+
![Frameworks Benchmark Results Graph Execution Time](screenshots/php-frameworks-bench-exectime.png)
52+
![Frameworks Benchmark Results Graph Included Files](screenshots/php-frameworks-bench-includedfiles.png)
5053

5154
|framework |requests per second (rps)|relative (rps)|peak memory|relative (mem)|
5255
|-------------------|------------------------:|-------------:|----------:|-------------:|
@@ -71,29 +74,13 @@ These are my benchmarks, not yours. **I encourage you to run on your (production
7174

7275

7376
#### OPCache On
77+
Check out the video for more information.
7478
[![Results with OPCache On/Off & How to add your framework](http://img.youtube.com/vi/Dk8YHQZ6jfY/0.jpg)](http://www.youtube.com/watch?v=Dk8YHQZ6jfY)
7579

7680

77-
## Benchmarking Policy
78-
79-
This is for the `main` branch.
80-
81-
* Frameworks installed via `composer` according to their official documentation.
82-
* Used the default configuration.
83-
* Considering the minimum changes on frameworks to run the benchmark.
84-
* Didn't remove any components/configurations even if there is no use for them.
85-
* We have a `controller` class to get the `Hello World` for each, based on the default template of each framework.
86-
* Turned off the `debug` mode and set the environment to `production` mode.
87-
* Considered general optimization for the production environment, like `--optimize-autoloader` for the composer.
88-
89-
Some frameworks are optimized more than others, so some people may think using default configuration is not fair. The dept of optimizing a framework depends on the experiences of the developer too, so it's the rabbit hole and there is no point in it. I think the default configuration of frameworks is a good starting point to get ranking.
90-
91-
If you find something wrong in my code, feel free to send a PR. But please note optimizing for the "Hello World" is not acceptable! Building the fastest `Hello World` application is not the goal of this project.
92-
93-
9481
## How to Benchmark
9582

96-
If you want to have benchmarks on `PHP extension frameworks` like `Phalcon`, you need to install the extension first based on its own documentation.
83+
If you want to have benchmarks on `PHP extension frameworks` like `Phalcon`, you need to install the extension first, based on its own documentation.
9784

9885
1- Download & Setup:
9986

@@ -104,7 +91,7 @@ $ git clone https://github.com/myaaghubi/PHP-Frameworks-Bench.git
10491
$ cd PHP-Frameworks-Bench
10592

10693
# optional
107-
$ nano benchmark.config
94+
$ nano config
10895

10996
# run the setup & follow the progress
11097
$ yes | bash setup.sh
@@ -115,29 +102,59 @@ $ yes | bash setup.sh
115102
```bash
116103
$ bash check.sh
117104
# bash check.sh -t pure-php
118-
# /------- pure-php: checking... done.
105+
# pure-php
119106
```
120107

121108
3- Run benchmarks:
122109

123110
```bash
111+
# bash benchmark.sh --help
124112
$ bash benchmark.sh
125113
```
126114

127115
4- Check the results:
128116
- web:
129117

130-
<http://localhost/PHP-Frameworks-Bench/>
118+
<http://127.0.0.1/PHP-Frameworks-Bench/>
131119

132120
- terminal:
121+
```bash
122+
# bash results.sh --help
123+
bash results.sh
133124
```
134-
bash show-table.sh
135-
```
125+
126+
127+
## Docker
128+
129+
Results with docker may not be reliable but in a situation you can use it like:
130+
131+
1- Change the `base` in `config` on the right port(`8080` considered):
132+
133+
```ini
134+
base="http://127.0.0.1:8080/PHP-Frameworks-Bench"
135+
...
136+
```
137+
138+
2- Run/download the docker:
139+
140+
```bash
141+
$ bash docker-apache.sh
142+
```
143+
144+
3- Run the benchmark:
145+
146+
```bash
147+
# run it in another terminal
148+
$ bash benchmark.sh
149+
```
136150

137151

138152
## Commands
139153

140154
```bash
155+
# use bash benchmark.sh --help
156+
$ bash benchmark.sh -f -rapache -t pure-php
157+
141158
# run composer update for frameworks
142159
$ bash update.sh
143160

@@ -149,27 +166,47 @@ $ bash clean.sh
149166
# clear the cache of frameworks
150167
$ bash clear-cache.sh
151168

152-
# show the results of the last benchmark
153-
$ bash show-table.sh
169+
# show the results table
170+
$ bash results.sh
154171
```
155172

156173
To specify frameworks, put them with `-t ...` after each command:
157174

158175
```bash
159176
# supported for `setup.sh`, `benchmark.sh`, `update.sh`, `clean.sh`, and `clear-cache.sh`
160-
# bash benchmarks.sh --help -h
177+
# bash benchmarks.sh --help
161178
$ bash benchmark.sh -t laravel-10.0/ slim-4.11/ ...
162179
...
163180
```
164181

165182

183+
## Add Your Framework
184+
Check out the [Benchmarking Policy](#benchmarking-policy), to get more information watch the video [OPCache On/Off](#opcache-on).
185+
186+
187+
## Benchmarking Policy
188+
189+
* Use `composer` to install frameworks according to their official documentation.
190+
* Use the default configuration.
191+
* Minimum changes on frameworks to have benchmarks.
192+
* Don't remove any components/configurations even if there is no use for them.
193+
* Include a `controller` class to get the `Hello World!` for each, based on the default template of each framework for `controllers`.
194+
* Turn off the `debug` mode and set the environment to `production` mode.
195+
* General optimization for the production environment, like `--optimize-autoloader` for the `composer`.
196+
197+
Some frameworks are optimized more than others, so some developers may think using default configuration is not fair. The dept of optimizing a framework depends on the skills/experiences of the developer too, so it's the rabbit hole and nonsense for ranking. Please **note** optimizing for the `Hello World` is not acceptable! Building the fastest `Hello World` application is not the goal of this project. I think the default configuration of frameworks is a good starting point to have a ranking.
198+
199+
If you find something wrong in my code, feel free to send a `PR`.
200+
201+
166202
## 🍔 Donate
167203
Don't forget to donate if you find it useful ☕ 🍺 🍸 🍔
168204

169205
ETH: 0x0ADd51D6855d2DF11BB5F331A3fa345c67a863b2
170206

171207
![Ethereum](screenshots/ethereum.jpg?raw=true "Ethereum")
172208

209+
173210
## References
174211
Note: This project is based on
175212
[php-framework-benchmark](https://github.com/kenjis/php-framework-benchmark), thanks to [Kenjis](https://github.com/kenjis). It is very old and abandoned, so I decided to split it from the origin and update it separately.

base/_functions.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
benchmark () {
22
fw="$1"
33
url="$2"
4-
output_wrk="output/$fw.wrk.log"
5-
output="output/$fw.output"
4+
output_wrk="output/$dir_datetime/$fw.wrk.log"
5+
output="output/$dir_datetime/$fw.output"
66

77
# check out the appropriate response is reachable
88
url_status=$(bash check.sh -t "$fw")
@@ -40,8 +40,7 @@ benchmark () {
4040

4141
rps=`grep "Requests/sec:" "$output_wrk" | tr -cd '0-9.'`
4242

43-
echo "rps: "
44-
numfmt --g "$rps"
43+
echo "rps: $rps"
4544

4645
# to make a small gap between the WRK and CURL
4746
sleep 1

base/hello_world.sh

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,21 @@
22

33
cd `dirname $0`
44
. ./_functions.sh
5-
. ../benchmark.config
5+
. ../config
66

7-
bm_name=`basename $0 .sh`
8-
9-
results_file="output/results.$bm_name.log"
10-
check_file="output/check.$bm_name.log"
11-
error_file="output/error.$bm_name.log"
12-
url_file="output/urls.log"
7+
bn_name=`basename $0 .sh`
138

149
cd ..
1510

16-
if [ -f "$results_file" ]; then
17-
echo "moving $results_file to $results_file.old"
18-
mv "$results_file" "$results_file.old"
19-
fi
20-
21-
if [ -f "$check_file" ]; then
22-
echo "moving $check_file to $check_file.old"
23-
mv "$check_file" "$check_file.old"
24-
fi
11+
mkdir -p output
2512

26-
if [ -f "$error_file" ]; then
27-
echo "moving $error_file to $error_file.old"
28-
mv "$error_file" "$error_file.old"
29-
fi
13+
export dir_datetime=`date +%y-%m-%dT%H-%M-%S`
14+
mkdir output/$dir_datetime
3015

31-
if [ -f "$url_file" ]; then
32-
echo "moving $url_file to $url_file.old"
33-
mv "$url_file" "$url_file.old"
34-
fi
16+
results_file="output/$dir_datetime/results.log"
17+
check_file="output/$dir_datetime/check.log"
18+
error_file="output/$dir_datetime/error.log"
19+
url_file="output/$dir_datetime/urls.log"
3520

3621
phpc=`curl -s "$base/libs/php_config.php"`
3722
echo "/------- PHP Config -------/"
@@ -52,7 +37,7 @@ do
5237
# continue
5338
# fi
5439

55-
if [ "$param_clean" = true ]; then
40+
if [ "$param_fresh" = true ]; then
5641
bash clean.sh
5742
bash setup.sh -t "$fw"
5843
fi

base/option_target.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function showHelp()
99
{
1010
cat << HEREDOC
1111
12-
Usage: bash check.sh [-t pure-php/ slim-*]
12+
Usage: bash check.sh [-t pure-php slim-*]
1313
1414
Optional Arguments:
1515
-h, --help Show this help message and exit
@@ -30,6 +30,7 @@ IFS=';'
3030
params=(`php ./libs/strreplace.php " -" ";-" " ${paramsin}"`)
3131
IFS=$oldIFS
3232

33+
init_benchmark=true
3334
for option in "${params[@]}"
3435
do
3536
case "$option" in
@@ -41,13 +42,19 @@ do
4142
fi
4243
;;
4344
-h|--help)
45+
init_benchmark=false
4446
showHelp;
4547
;;
4648
""|" ")
4749
;;
4850
*)
51+
init_benchmark=false
4952
echo "\"${option}\" not available"
5053
exit 1
5154
;;
5255
esac
53-
done
56+
done
57+
58+
if [ "$init_benchmark" = false ]; then
59+
exit 1
60+
fi

base/show_fw_array.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
cd `dirname $0`
44
cd ..
55

6-
. ../benchmark.config
6+
. ../config
77

88
# include framework list
99
targets="$frameworks_list"

0 commit comments

Comments
 (0)