Skip to content

Instantly share code, notes, and snippets.

@simonwheatley
Created March 1, 2012 11:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonwheatley/1949105 to your computer and use it in GitHub Desktop.
Save simonwheatley/1949105 to your computer and use it in GitHub Desktop.
Uses Curl to get the response time for a webpage, also regexes out the page gen time (this last relies on WP Super Cache's "Dynamic page generated in X.XX seconds." HTML comment)
#!/bin/bash
# My script below is based on this one:
# http://unixbhaskar.wordpress.com/2010/11/12/measure-website-response-time-through-curl/
if [ -z $1 ]
then
echo "Please pass a URL to measure the response time for, e.g."
echo "sh infinite_response_time.sh http://google.com/ cookie1=123\;cookie2=abc"
exit
fi
URL=$1
COOKIE=$2
echo "Did you remember to backslash escape in the cookies param (if you used it)?"
echo ""
echo "Time: to connect / start transfer / total time / page generation"
# An infinite while loop…
while [ 1 ]
do
# Get the transfer and connection times
result=`curl --cookie "$COOKIE" -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total} $URL`
STAT1=`echo $result | gawk -F: '{ print $1" / "$2" / "$3}'`
# Get the page gen time.
# Comment out this line if you don't want the Super Cache page gen time
result=`curl --cookie "$COOKIE" -s $URL`
# Dynamic page generated in 1.103 seconds.
STAT2=`echo $result | sed "s/.*Dynamic page generated in \(.*\) seconds.*/\1/g"`
# If you don't have the page gen time, you'll need the next rather
# than the subsequent line.
# echo "$STAT1"
echo "$STAT1 / $STAT2"
# Gently does it
sleep 5s
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment