Average website response time bash script

Ok i make a little bash script to test a particular website response time. This is done via the command line through a bash script. Anyway, here's the script code.


#!/bin/bash

CURL="/usr/bin/curl"
echo -n "Please pass the url you want to measure: "
read url
URL="$url"
count=1;
total_connect=0
total_start=0 
total_time=0
	echo " Time_Connect Time_startTransfer Time_total ";
while [ $count -le 100 ]
do
	result=`$CURL -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total} $URL`
	echo $result;

	var=$(echo $result | awk -F":" '{print $1, $2, $3}')
	set -- $var

	total_connect=`echo "scale=2; $total_connect + $1"  | bc`;
	total_start=`echo "scale=2; $total_start + $2" | bc`;
	total_time=`echo "scale=2; $total_time + $3" | bc`;
	count=$((count+1))
done
echo "average time connect: `echo "scale=2; $total_connect/100" | bc`";
echo "average time start: `echo "scale=2; $total_start/100" | bc`";
echo "average time taken: `echo "scale=2; $total_time/100" | bc`";

What the above does is to prompt you for a url to test and run it for 100 times on your machine and print out the average response time from the website server to your machine.

Assuming you save the above file in 'shell', you will call the above script via 'bash ./shell' and it will prompt you for an url and start executing the url for 100 times and gives you an average response time.

P.S: the above script required you to install bc, you can install via yum install bc or sudo apt-get install bc 😉

Yii CClientScript Disable RegisterScript

I though this might be useful since its not widely spread yet. There will be times when you want to disable some scripts on CClientScript so that your ajax or JSON will print properly. In this case, depending on what you want to disable, these methods might be helpful.

Disable JavaScript or CSS files in CClientScript

Well, you if want to disable JavaScript or CSS files that were included via registerCssFile or registerScriptFile you can fire the following code into your filer or anywhere your action is being fired

        $cs = Yii::app()->clientScript;
        $cs->scriptMap['jquery.js'] = false;
        $cs->scriptMap['bootstrap.min.css'] = false;
        $cs->scriptMap['bootstrap.min.js']  = false;
        $cs->scriptMap['bootstrap-yii.css'] = false;

scriptMap will disable the file mentioned (example jquery,js) and replace with 'false', this is similar to how you would go about optimizing js and css scripts on Yii as well 😉

Removing CSS or JavaScript code in CClientScript

this will be a little bit tougher than you would imagine since the array 'scripts' which suppose to be available isn't really 'public' but you can still remove the code via the following,

Yii::app()->clientScript->registerScript('mykey', "jQuery('{$selector}').{$name}({$options});");

basically, to remove the custom script i have wrote above, i will fire something like this

Yii::app()->clientScript->registerScript('mykey', false);

basically i am overwriting whatever i have registered and this will remove the custom script that i have written. Neat isn't it 😉

Remove every single custom scripts on CClientScript

if the above isn't what you were looking for, may be you are like me who manage to remove custom scripts using the above method but the script tags still appear, in this case, i fire the following code to stop my headache

        $cs = Yii::app()->clientScript;
        $cs->reset();

since we can't make 'hasScripts' to be false (which is the reason why the script tags still appear), we will reset all the calling scripts instead. but this won't always work as neat as you would want to but its a good solution so far.

Disable JavaScripts entirely on CClientScript

Well, its so irritating that i wanted everything to be disable on cclientscript, in this case, use the following,

        $cs = Yii::app()->clientScript;
        $cs->reset();
        $cs->enableJavaScript = false;

This will ensure everything is disabled.

This should be useful for people working on Ajax, restful and JSON implementation on Yii 😉