Friday, June 18, 2010

In the Rain ...

Drenching in the early rain,
On a slow moving train,
In some unknown pain,
Wondering again & again,
In life what's there to gain,
Shiny stone or some dull grain,
In reality, all is in vain,
Every deed has some stain,
Only that does remain,
Wishing to stay inside int main

Page Loaded in X seconds.....

It is very simple to display the page load time & number of mysql queries executed on a page. It helps us calculate load times for pages, and differentiate which pages need more optimization. On a PHP, MySQL server use these two functions for the task.

function getTime() {
     $currTime = microtime();
    $time = explode(" ", $currTime);
     $tot = $time[1] + $time[0];
    return $tot;
}
function  getQueryCount() {
    $sql = "SHOW SESSION STATUS LIKE 'Questions'";
     $res = $mysql_query($sql);
    return $res['Value'];
}
The function getTime returns the current time accurate upto the millisecond. We record the starting and ending time of the script. The difference is the execution time.

Similarly, we note the number of queries executed at the start of the session and then at the end. The difference is the queries executed. Finding out the number itself is 1 query.
Note: mysql_connect() must be called before using getQueriesCount().


Below is a test script. Save it as test.php and run it from Apache. You could fill in the corresponding values at the top of the script.


$db_user "test";$db_pass "test";$db_db "test"; 
$query[0] = "select * from posts";
$query[1] = "select * from categories";

function getTime() {
    $currTime microtime();    
    $time explode(" "$currTime);
    $tot $time[1] + $time[0];   
    return $tot;
}
function getQueryCount() {
    $sql "SHOW SESSION STATUS LIKE 'Questions'";
    $res mysql_query($sql);    
    $row mysql_fetch_array($res);
    return $row['Value'];
}


// Begin recording$startTime getTime(); 
mysql_connect("localhost""test""test"); 
mysql_select_db("test");
$startQueries getQueryCount();
 
// Start of script 
foreach($query as $q) {   
    echo "Running query: " $q " ";    
    $res mysql_query($q);
}
// End of script
 
$endQueries getQueryCount();

$totalTime round(getTime() - $startTime5);
$totalQueries $endQueries $startQueries 1; 
// End recording
echo "
     Page Loaded in " $totalTime " seconds. 
     Total "$totalQueries ." queries.";
?>

Its output is.
Running query: select * from posts
Running query: select * from categories


Page Loaded in 0.51291 seconds. Total 2 queries.

Sunday, June 13, 2010

Speeding up Firefox

Firstly disable unwanted addons. Then do the following. It will improve the page load times.

Type "about:config" in the url bar, and change the values of the following properties
  • network.http.pipelining;    true
  • network.http.pipelining.maxrequests;    10
  • network.http.pipelining.ssl;    true
  • network.http.proxy.pipelining;    true
  • network.dns.disableIPv6;    true