Skip to content

Instantly share code, notes, and snippets.

@electrawn
Forked from brentertz/ab.sh
Last active March 16, 2022 10:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save electrawn/6815208 to your computer and use it in GitHub Desktop.
Save electrawn/6815208 to your computer and use it in GitHub Desktop.
Wordpress logged in user performance test with apache bench
#!/bin/bash
# For cygwin, APACHEBENCH could be /usr/sbin/ab2, else ab will suffice on linux/unix systems.
APACHEBENCH=ab
COOKIE_JAR="ab-cookie-jar"
USERNAME="foo@bar.com"
PASSWORD="password"
HOST="127.0.0.1"
BASEURL="http://$host"
LOGINURL="$baseurl/wp-login.php"
ADMINURL="$baseurl/wp-admin"
POSTDATA="log=$user&pwd=$password&rememberme=forever&wp-submit=Log%20In&redirect_to=$adminurl/"
[ -e $COOKIE_JAR ] && rm $COOKIE_JAR
# this will login to wp and download the session cookie
curl --insecure --connect-timeout 60 --cookie-jar $COOKIE_JAR --data $POSTDATA $LOGINURL
[ -e $COOKIE_JAR ] && echo "WP cookie created: $COOKIE_JAR"
# now you have a WP session cookie!
# Pipe Audit: print file, ignore first 4 lines of curls cookie jar,
# only print records tab delimited 6 and 7 from the jar, convert newlines for later header injection.
COOKIES=$(cat $COOKIE_JAR | tail -n +5 | awk '{print $6"="$7}' | tr '\n' ';')
echo "Cookies String is:"
echo $COOKIES
echo "=================="
echo "Testing Posts:"
$APACHEBENCH -n 20 -c 2 -H "Cookie: $COOKIES" $ADMINURL/edit.php
echo "Testing Pages:"
$APACHEBENCH -n 20 -c 2 -H "Cookie: $COOKIES" $ADMINURL/edit.php?post_type=page
echo "Testing Front Page:"
$APACHEBENCH -n 20 -c 2 $BASEURL/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment