CartMetrix - Do you know yours?

7/18/2007

PHP Stopwatch Class to Time and Log Script Execution

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: 31%

7/11/2007

How Much Censoring Does Google Do?

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: 26%

7/7/2007

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

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. Restart the server… still no Qmail. Looking through the Qmail settings in Plesk I noticed the server owner had ticked _all_ RBL. Each blacklist check requires a distinct call to the specified RBL service for every email. A busy server with many domains might have several thousand email addresses on it. With only a hundred SPAMs a day to each email address (I get 400+ a day on my main accounts), its easy to see how Qmail could get worked over with a million RBL checks a day. Not to mention the load added to the RBL servers themselves.

I un-ticked all but two RBL checks and Qmail started right up. There is a limit to how many RBL services Plesk Qmail can support. I would recommend only a couple. If many SPAMs are still getting through select a few different ones, don’t just blindly add more checks. More is not always better. Sometimes more is just more. I suggest testing various combinations until you find the best for your server and users.

Another worthwhile note is that these RBLs sometimes go away or are inaccessible for a period of time. If you are trying to use one that is down, all of your mail will be delayed while each attempt has to time out before Qmail can process the mail further. If you have problems with sluggish mail check the sites of the RBLs in use to verify they are indeed active.

Popularity: 27%

7/4/2007

Zen Cart Patch Needed For Admin Security

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 help with this patch, I can install for $25.
(more…)

Popularity: 25%


damonparker.org is proudly powered by WordPress
Entries (RSS) and Comments (RSS).

copyright © 2002-2008 damonparker.org. all rights reserved.

Close
E-mail It