<?php
# COPYRIGHT
# Speed Comparision (c) 2010 Scott Connell
# Redistribution without permission is forbidden.
# Source http://www.scottconnell.com
# Last Updated 12/26/2010
#
# SET VARIABLES ########################
# Change the header path, and footer path,
# to your full directory path if neccessary.
$header_path = "header.php";
$footer_path = "footer.php";
# END SETTING VARIABLES #################
if($settingsArray = @ini_get_all())
{
$allowArray = $settingsArray["allow_url_fopen"];
$globalvalue = $allowArray["global_value"];
$localvalue = $allowArray["local_value"];
if(!($globalvalue && $localvalue))
{
$title = "Whoops! - php.ini variable not set";
include_once($header_path);
print "<p>It does not appear that you have allow_url_fopen = On, set in your php.ini file. This program will not work until you set this variable.</p>\n";
exit(include_once($footer_path));
}
}
function printForm()
{
global $www;
$action = $_SERVER["PHP_SELF"];
print <<<ENDHTM
<form method="post" action="$action">
<p>http:// <input type="text" name="www" value="$www"/> <input type="submit" value="Submit"/></p>
</form>
ENDHTM;
}
if($_REQUEST['www'])
{
$domain = strtolower($_REQUEST['www']);
$xArray = @parse_url($domain);
if(!$xArray["scheme"])
{
$domain = "http://" . $domain;
$xArray = @parse_url($domain);
}
$xProtocol = $xArray["scheme"];
$xHost = $xArray["host"];
$xPort = $xArray["port"];
$xUser = $xArray["user"];
$xPass = $xArray["pass"];
$xPath = $xArray["path"];
$xQuery = $xArray["query"];
$xFragment = $xArray["fragment"];
$domain = $xProtocol ."://". $xHost . $xPath . ($xQuery?"?":"") . $xQuery;
$www = $xHost . $xPath . ($xQuery?"?":"") . $xQuery;
setcookie("URL", strtolower($www), time()+(60*60*24*30), "/"); // 30 days
$title = "Speed Comparison - Compare load speed against Yahoo and Google.";
include_once($header_path);
printForm();
$speedstart = microtime();
$readurl = @fopen($domain,"r");
$speedend = microtime();
$diff = number_format(((substr($speedend,0,9)) + (substr($speedend,-10)) - (substr($speedstart,0,9)) - (substr($speedstart,-10))),4);
$milli = $diff*1000;
if(!$readurl)
{
print "<div><p>Your site is offline</p></div>\n";
}
else
{
print "<div><p>Your site: " . $milli . " milliseconds</p></div>\n";
}
$speedstart = microtime();
$readgoogle = @fopen("http://www.google.com","r");
$speedend = microtime();
$diff = number_format(((substr($speedend,0,9)) + (substr($speedend,-10)) - (substr($speedstart,0,9)) - (substr($speedstart,-10))),4);
$milli = $diff*1000;
if(!$readgoogle)
{
print "<div><p>Google is offline</p></div>\n";
}
else
{
print "<div><p>Google: " . $milli . " milliseconds</p></div>\n";
}
$speedstart = microtime();
$readyahoo = @fopen("http://www.yahoo.com","r");
$speedend = microtime();
$diff = number_format(((substr($speedend,0,9)) + (substr($speedend,-10)) - (substr($speedstart,0,9)) - (substr($speedstart,-10))),4);
$milli = $diff*1000;
if(!$readyahoo)
{
print "<div><p>Yahoo is offline</p></div>\n";
}
else
{
print "<div><p>Yahoo: " . $milli . " milliseconds</p></div>\n";
}
}
else
{
$title = "Speed Comparison - Compare load speed against Yahoo and Google.";
include_once($header_path);
if(isset($_COOKIE['URL']))
{
$www = $_COOKIE['URL'];
}
printForm();
}
include_once($footer_path);