July 2007

Timing code execution is an often overlooked debugging tool. On a current large project we are doing a lot of work interfacing with multiple SOAP implementations on multiple servers and through multiple vendors. When script execution slows down considerably (or stops responding altogether) we needed to know which SOAP calls were causing the slowdown.

Using code and ideas from php.net/microtime I devised this PHP class to handle the timing tasks.

class StopWatch
{
    private $round      = 3;
    public  $logfile    = 'time.log';

    function __construct($logfile = '')
    {
        $this->start = microtime();
        if($logfile != '')  $this->logfile = $logfile;
        $this->fp = fopen($this->logfile, 'a+');
    }

    function __destruct()
    {
        fclose($this->fp);
    }
   
   
    function now()
    {
        $start  = $this->math($this->start);
        $now    = $this->math();
        return round($now - $start, $this->round);
    }

    function math($time = false)
    {
        if ( !$time ) $time = microtime();
        $temp = explode(' ', $time);
        return $temp[0] + $temp[1];
    }

    function write_log($loc, $data)
    {      
        return fwrite($this->fp, date("Y-m-d H:i:s").' '.$loc.': '.$data."s \n");          
    }
   
}

Download class.StopWatch.php

Usage

Include the class in your application and create a new instance at the very top of the code.

$sw = new stopwatch();
$time1 = $sw->now();

… snip more code …

$time2 = $sw->now();
$sw->write_log('CODE-LOCATION', $time2-$time1);

Substitute CODE-LOCATION with the function name or other identifier being timed.

In this case, the stopwatch class logged this data…

2007-07-18 05:00:07 GetVendor: 1.311s
2007-07-18 05:01:10 GetLocationByZip: 62.439s
2007-07-18 12:19:18 GeneratePin: 12.232s
2007-07-18 12:19:24 GetVendor: 5.377s
2007-07-18 12:20:31 GetLocationByZip: 66.779s

It is now trivial to see which SOAP call is the culprit (GetLocationByZip) and which vendor to contact.

Popularity: 6%

{ 3 comments }

How Much Censoring Does Google Do?

by damonp on July 11, 2007

in Random Thoughts

I was playing with a backlinks checker earlier and stumbled upon some interesting Yahoo and Google link love facts…

Yahoo doesn’t seem to hold a grudge against their rival Google (quickly becoming everyone’s rival). Yahoo lists plenty of backlinks in its search results for google.com. Google isn’t currently returning the favor for yahoo.com. In fact Yahoo shows more backlinks for Google than Google does for itself. Surely Google caps its results.

Try directly at Google with a search like this:
For Yahoo at Google
http://www.google.com/search?q=link:yahoo.com
0 Pages

For Google itself
http://www.google.com/search?q=link:google.com
1,600,000 Pages.

Or even going to Google’s advanced search page and using their Links search,

Links – Find pages that link to the page

http://www.google.com/advanced_search

Try both yahoo.com and google.com there.

Google’s backlinks are known to be only a small percentage of what are actually crawled, but 10% of ZERO is still ZERO. Given the round number 1,600,000, I’d say the results are capped.

Over at Yahoo, the results are quite different.

For Google at Yahoo
https://siteexplorer.search.yahoo.com/search?p=http%3A%2F%2Fgoogle.com
Currently 17,475,629 pages.

For Yahoo at Yahoo
https://siteexplorer.search.yahoo.com/search?p=http%3A%2F%2Fyahoo.com
Currently 1,675,687,898 pages. That’s 1.6 billion.

I have always defaulted to Google’s search. Originally because that was all they did. With the Yahoo Directory and all of Yahoo’s other offerings, I assumed years ago that since Google concentrated on search, their tool would be better. Now I’m wondering what I may be missing.

It is every business’ prerogative to do what works best for them. Internet search is becoming a utility though. Millions of people depend on their daily bread for traffic from these utilities. Is there anyone monitoring them?

Popularity: 1%

{ 3 comments }

Plesk Qmail and Remote Black Lists (or Plesk says Qmail not started)

7 July 2007

With the recent increase in SPAM volume, I have had two clients contact me with Qmail problems on Plesk servers. The error they were receiving was in the status page of the Plesk admin panel. Under the status line for Qmail, Plesk said Qmail not started Several attempts to restart Qmail produced the same results. [...]

Read the full article →

Zen Cart Patch Needed For Admin Security

4 July 2007

Zen Cart has released a patch for all versions v1.2 through v1.3.7 that fixes a serious security hole in the admin login/password reset system. I strongly advise all current ZenCart users to see to it that this patch is performed on their systems. The patch takes less than fifteen minutes to complete. If you need [...]

Read the full article →