Archive for March, 2006

Spammers and Bots

For the last week the server has been under siege by the spammers. Before I activated the automatic reject setting, my email was flooded with 1500 or so moderation requests. Chances are anyone trying to comment over the weekend or earlier met the emergency comment shutdown mode in Serendipity for those occassions when the spammers are in overdrive. To ease off the restrictions I’ve bumped up the required delay between comments, added some additional search terms, and removed the emergency shutdown option – it’s just preventing comments from legitimate users at this stage.

Sort of while doing this I also took a look at another highlighted issue – bots. The number and frequency of bots crawling the blog and forums has increased a great deal since the start of the year. Normally I don’t mind search bots, but a few of these are hitting again, and again, and again. Now checking in is normal – but what’s all the multiple daily hits about? How many times is the blog being downloaded a day at the expense of sucking up my personal paid for bandwidth?

Performance Monitoring for ADOdb-Lite?

A while back I said I was thinking vaguely about adding performance monitoring into ADOdb-Lite. The news is that I started doing so today. The reasoning is fairly obvious – ADOdb’s perfmon library is a very useful tool even if it is underused, and I want to use it. Since nagging someone else about a feature I want is pointless (its open source!), I’m adding it myself – and hopefully well enough to see it in a release one day.

Day 1 was a two hour session taken up primarily in reading and understanding the ADOdb source code – man, it’s like wading through a bomb site at times. adodb.inc.php is huge! Anyways, I noted a few things and, just to make it clear, I was reading a July 2005 version (so anything noted by me could well have been changed since). Anyways, main points on Perfmon in ADOdb (as of July ’05):

- Perfmon is not workable with mysqli driver; there’s a small possible bug where the driver class supplies the $dataProvider property with the value “native”. Perfmon deliberately blocks this value – and the mysql driver uses the “mysql” value. So at the expense of some unknown issue and assuming what works for mysql qorks for mysqli, changing this to “mysqli” from “native” works fine.

- ADOdb output is escaped via htmlspecialchars(). Same as for ADOdb-Lite by default. Personally I prefer htmlentities() with ENT_QUOTES. Setting the character encoding is usually advisable to prevent charenc misinterpretations. Nag, nag, nag…;-)

- Output and PHP is mixed up. Never liked that, never will.

- Code uses the long names for superglobals – I don’t use old PHP versions, and I have the PHP6 CVS installed, so I’m changing that one for better or worse…

So after the reading I looked at what I needed to do. Given Perfmon is fairly standalone the simplest path is just to dump the code into ADOdb-Lite with minimal changes as follows:

- add a new property, $_logsql, to ADOConnection
- add a new method, LogSQL(), to ADOConnection
- stick the driver specific subclasses of the main perfmon class into the driver directory for each DBMS
- add a NewPerfMonitor() function to adodb.inc.php

Done, dust, test and finish… The approach isn’t part of the module system – like DataDictionary perfmon is called outside the connection object so that route seems to be of little real value. NewPerfMonitor() does all the legwork, and its use is pre-existing already if you use ADODB in code, so BC and all that prevailing…

I did a lot of the above in the second hour, tidied up and modified the source where necessary to make it ADOdb-Lite compatible, and ran a few tests. It still won’t work, but that’s for the moment because the $_logsql property acts as a switch which is, well, switched, on every query (to avoid logging the sql query FOR logging). It’s one of those confusing “track the value” puzzles I’m not up to getting my brain around at 11pm after having a few drinks earlier (rugby match – Ireland won over at Twickenham beating England for the Triple Crown – now if only Wales won…).

Tomorrow I’ll see about finishing it off, maybe tidying up output, and sticking a version online somewhere for someone else to look at and tell me what a bad lazy programmer I am…;-). Anyways, perfmon for ADOdb-Lite, soon to be checked off my todo list.