Wednesday, March 4, 2009

Symfony: Error Logging Hack

Symfony is an excellent PHP framework used on Colnect. As any piece of software, however, it has its shortcomings. The good thing is that I can hack it to fit my needs when some things are not to my likings. A recent hack I've done (and should have done a long time ago) is about the error logs. Though the guidebook to Symfony describes logging at length I couldn't figure out how to easily add some useful information to any Exception thrown on my production machine.

The following hack can be has been customized for my needs but you can change it to your preferences. It'll change the output Symfony places in the PHP error log file.

What the Hack Does?


A boring Exception such as:
[04-Mar-2009 17:20:25] Action "coins/collect" does not exist.


Will become:
[04-Mar-2009 17:20:25] CODE[0] MESSAGE[Action "coins/collect" does not exist.]
FILE[.\config_core_compile.yml.php] Line[715]
REQUEST[/it/coins/sdlk] REFERER[]
AGENT[Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6] ADDR[127.0.0.1]


How To?


Find sfException class (should be /symfony/lib/exception/sfException.class.php) and add the following method:



public function getMessageFull() {
$exception = is_null($this->wrappedException) ? $this : $this->wrappedException;

try {
$sReq = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
$sRef = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$sUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$sRemoteAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';

$sErrMessage = "CODE[".$exception->getCode().'] MESSAGE['.$exception->getMessage()."]"
."\n\tFILE[".$exception->getFile()."] Line[".$exception->getLine()."]"
."\n\tREQUEST[$sReq] REFERER[$sRef]"
."\n\tAGENT[$sUserAgent] ADDR[$sRemoteAddr]\n"
;
}
catch (Exception $e)
{
$sErrMessage = $exception->getMessage();
}

return $sErrMessage;
}


Customize this method to your needs. Make sure it doesn't raise any exceptions itself.
Now you need 2 more small changes in both sfException.php and sfError404Exception. Change the line:
error_log($this->getMessage());

to:
error_log($this->getMessageFull());


More Enhancements?


It's your call. You can email yourself an alert, include more system-specific pieces of information or use the code as is. It's obviously not the cleanest solution possible but it works for me and hope it helps you.

Wednesday, February 25, 2009

3,500 collectors on Colnect

Yesterday Colnect has passed the mark of 3,500 registered collectors. This is an increase of over 17% during the last 2 months. Just before starting this year, Colnect had passed the 3,000 collectors mark. Considering the fact that ridiculously little marketing work has been done (~$50 spent on ads...), I see this as a very respectable achievement that continues the growth that started when Colnect V2 was released.

How do collectors learn about Colnect?


As Colnect allows collectors to manage their personal collection and semi-automatically manage swaps with other collectors from around the world, it's the collectors' own interest to have their collector friends join the site. Why would a collector go through the swap and wish lists of another collector manually when a match to his own lists can be done using a single click?

So what's next?


Colnect will expand to more collectible fields as requests come from existing members of the community. Some requested premium services are also planned.

Thursday, February 19, 2009

BE CAREFUL when using both AdSense + AdWords by Google


Do you have a website and using both AdSense and AdWords? If so, this post will interest you. You may start by looking at the attached picture.

AdWords and AdSense are the different sides of the same coin and Google is in the middle, biting on the metal. AdSense allows website owners to show different ads from different advertisers on their website and receive revenues for it. AdWords allow you to advertise your website on many other websites running AdSense. Google takes its commission for providing both these services. Though many other competing programs exist on the web, Google's generally have good reputation.

Advertising my site on my site?!?!?!


This morning, I was amazed to see an ad to my website for collectors on the same site! Had I clicked this ad, my AdWords account would have been billed for the click while my AdSense account would have received some revenue. Obviously the latter would be lesser since Google get their cut. This is, of course, ridiculous and should be automatically prevented by Google. Apparently, it isn't. Just to ensure you that I'm not an idiot, the ad is for colnect.com and the website is on the same domain - colnect.com

I usually view my own site with ads disabled so I don't accidentally click an ad and violate the terms of service. This time I was at a friend's house and am quite happy to have stumbled upon the aforementioned bug/feature.

Quick Remedy




Both accounts allow you to use filters and I've now added "competition filters" for my AdSense account that will prevent showing ads for any of my domain. It's also possible to filter out sites on AdWords but this can seemingly be done only on the campaign level so if you're running many different campaigns, it'll become tedious. See the attached pictures.

Link and Search

Did you like reading it? Stay in the loop via RSS. Thanks :)