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

Saturday, May 1, 2010

Flash Player on Ubuntu

For installing Flash Player on Ubuntu Linux (8.04+) with Mozilla Firefox 3.6+
Alternate methods are available, but this script makes installation very easy.
  • Download the file attached and extract it. (Get64bitFlash-0.2.3.tar.gz)
  • Close all browsers.
  • Run the script as using sudo.
  • Restart Firefox.
  • Verify the plugin under add-ons tab.
Note:  This script downloads a file from the Adobe Web site. If there is any errors while running the script, do this.
  • Download the Flash plugin file. (Alternate: Link)
  • Move the tar file to /tmp/plugintall
  • Download and run the modified script. (Get64bitFlash)

Source: Source

Sunday, March 21, 2010

MySQL Tips

Try stopping the mysql daemon
CODE
/etc/init.d/mysql stop

Run
CODE
mysqld_safe --skip-grant-tables &

Enter as root
CODE
mysql -u root -p


To change root password
CODE
mysql client - mysql -u root

and write
CODE
use mysql
update user set password=PASSWORD(”NEW-ROOT-PASSWORD”) where User=’root’;


Source

Saturday, February 27, 2010

else if()

Writing conditional assignment without using else.
In other words, creating a custom else if.
My guess is that the coder doesn't like using
keywords containing 's'.
And in this case expecting operators would be a sin. :)
 
while(true)
{
    if(mainType == 7)
    {
        subType = 4;
        break;
    }

    if(mainType == 9)
    {
        subType = 6;
        break;
    }

    if(mainType == 11)
    {
        subType = 9;
        break;
    }

    break;
}
 
 
Source  

Friday, February 12, 2010

LOVE-ly Limericks...

A new Valentine...
The weather is all but fine,
the sun does hardly shine, 
alone I don't wanna dine, 
all I wish is for a Valentine

Thursday, February 11, 2010

Lame Limericks - The Beginning

Here are my lame limericks, 
output of my best picks,
which aren't any gimmicks,
for gaining a few clicks.
Churned by my brain, 
with little or no strain, 
reading it is no pain,
so visit again and again.


More will keep coming, so keep visiting. :)