Skip to content

Instantly share code, notes, and snippets.

@fhdalikhan
Forked from eusonlito/ab-laravel-php.sh
Created May 7, 2019 04:53
Show Gist options
  • Save fhdalikhan/c738cd29a4ce69f2f81617f9cc0a7cda to your computer and use it in GitHub Desktop.
Save fhdalikhan/c738cd29a4ce69f2f81617f9cc0a7cda to your computer and use it in GitHub Desktop.
Benchmark project with different Laravel versions vs PHP versions
#!/bin/bash
phps="7.1 7.2 7.3"
laravels="5.5 5.6 5.7 5.8"
requests="1000"
concurrencies="1 10 100"
native="$1"
function csv {
for t in requests time; do
for n in $requests; do
for c in $concurrencies; do
printf "$1" >> storage/logs/ab-$t-$n-$c.csv
done
done
done
}
rm -rf storage/logs/*.log storage/logs/*.csv
csv ",PHP 7.1,PHP 7.2,PHP 7.3"
for l in $laravels; do
rm -rf vendor
rm -rf bootstrap/cache/*.php
sed -i 's/"laravel\/framework": "[^"]\+"/"laravel\/framework": "'$l'.*"/' composer.json
composer update --no-scripts --no-dev
composer install --no-dev
if [ "$native" == "true" ]; then
php-cs-fixer fix --rules=native_function_invocation --allow-risky=yes vendor/laravel/framework/src/Illuminate/
fi
csv "\nLaravel $l"
for p in $phps; do
printf "\n\nTesting Laravel $l on PHP $p\n\n"
nohup php$p -S localhost:4000 server.php > /dev/null 2>&1 &
sleep 5
for n in $requests; do
for c in $concurrencies; do
printf "\nab -l -n $n -c $c http://127.0.0.1:4000/\n\n"
log="storage/logs/ab-laravel-$l-php$p-n-$n-c-$c.log"
ab -l -n $n -c $c http://localhost:4000/ > $log
printf ','$(grep -o 'Requests per second:\s\+[0-9\.]\+' $log | awk -F' ' '{print $4}') >> storage/logs/ab-requests-$n-$c.csv
printf ','$(grep -o 'Time per request:\s\+[0-9\.]\+' $log | awk -F' ' '{print $4}' | tail -1) >> storage/logs/ab-time-$n-$c.csv
done
done
kill -15 $(lsof -ti tcp:4000)
done
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment