Great way to deal with trolls on your blog

Reading 37signals’ Signal vs. Noise blog today, I came across what I think is a great example of how to deal with trolls on your blog (would also work on a forum/bulletin board).

image of a blog comment with troll label and dunce hat

The problem with one of the most common responses to trolls (i.e. banning them), is that they just come right back and return to grabbing people’s attention with inflammatory messages and starting flame wars. This is a much more elegant solution: rather than getting rid of the offending user, clearly identify them so others won’t feed the troll, shame them with the dunce cap, and make their message slightly harder to read.

Apparently phpBB, a common web forum package in PHP, comes with some similarly creative ways of dealing with trolls, which include silencing them so that it looks to the troll like all their posts are going through, but no one is reacting. Apparently in the above case, the offending user was being impersonated, so I’ve blurred the username (not that it really matters much), but I don’t imagine a troll would stick around very long under such circumstances.

And as an aside, the SvN blog post itself was pretty interesting, discussing how 37signals had taken advantage of an interesting RoR “performance management solution” called New Relic to optimize their server configuration and cut response times drastically.

If only there were something similar for some of the PHP frameworks (maybe there is?).

More cakePHP tips

Continuing from my last post on choosing a php web development framework, here are some more tips on cakePHP that you may not otherwise come across as quickly

  • if you change your database (as configured in app/config/database.php) make sure to delete the files in app/tmp/cache/models (see here)
  • cakePHP will do some nice automation work for you if you create created and modified fields in your database tables. But for cake to do its magic, the default values of those fields have to be set to null, otherwise cake will assume they’re already set and won’t alter them
  • if you need to set variables in your controller that will be accessible in your layouts, just append the string “_for_layout” to the variable name, and use Set as you normally would in the controller, e.g. $this->set('whatever_for_layout', $variable); The variable will then be accessible in the layout as it would in a view, e.g. <?php echo $whatever_for_layout; ?>

Choosing a PHP web application framework

Having dabbled in ruby on rails but eventually given up for no better reason than that my web hosting provider (site5) is particularly difficult to get recent version of rails up and running (issues with rubygems and rails edge are attested in numerous places on the site5 forums), I set my sights on choosing a PHP web application framework. There are several reasons this makes better sense for me than rails:

  • Learning more about PHP will probably better aid me in my other work than learning more about ruby, as the three most common content management systems (Joomla!, drupal, and wordpress) are all PHP
  • support for PHP is much better on site5 than support for rails; support for PHP is in general much more common than support for rails
  • PHP-based web app frameworks don’t require anywhere near the memory footprint required by rails apps, which leads to…
  • … scaling issues? Actually, this isn’t really a concern. Most people have way bigger concerns than scaling like, say, getting their app to be popular enough that they have to worry about scaling. And while the spectre of Twitter and its many services outages that have been attributed to rails may be somewhat worrying, rails’ purported scaling difficulties are not foremost in my mind. There was a great comment on slashdot a while ago (wish I could find it…) that discussed how scaling problems can be greatly compounded by algorithm design and that, with well-designed algorithms most serious scaling issues can be nipped in the bud

So on to the PHP web app frameworks… What was I looking for in a framework? (for a comparison chart, see here)

  • lack of bloat
  • decent documentation
  • significant developer/support community
  • MVC architecture (does that go without saying?)
  • decent templating system
  • caching preferably
  • ability to extend easily with other classes
  • AJAX integration
  • PHP 5 would be nice

To make a long story short, after a fair bit of comparison and review, I narrowed it down to cakePHP and CodeIgniter. Though both seem very strong, in the end I decided to go with cakePHP based mostly on this write-up by Chris Snook a respectable web developer and fellow Canadian.

As Chris writes, cakePHP does indeed make querying dead simple. And their philosophy of “convention over configuration” means that though it may take a little bit of getting used to (and some occasional forgetting of whether to camelCase or separate_by_underscores) the amount of file editing for configuration purposes is greatly reduced.

So far I’ve been very happy with cakePHP and have been able to get some fairly complicated apps up and running in under a day (cakePHP offers powerful scaffolding similar to rails), though I do have to agree that the documentation could still use some more work, and I find myself often having to compose obfuscated Google search queries for things that aren’t easily findable in the manual or API docs.

Some quick tips for those getting the hang of cakePHP (version 1.2):

  • If you’re using UTF-8 collation in your database tables and web pages, you can make the necessary changes by adding the following line to your database.php configuration file:
    'encoding' => 'UTF-8'
  • don’t forget that just because you’re working with a copy of, say, a single record from your Posts model as $post in your views, you still need to reference fields like this:
    $post['Post']['title']
  • want to get rid of those SQL debug messages at the bottom of all your pages, and you tried changing the layout but they won’t go away? Edit /config/core.php and change the ‘debug’ from 2 to 0. You can also alter the debug level by controller method — see this post from the cakePHP Google group.
  • a stupid mistake you may make too: if you’re trying to use php variable in a cakePHP findAll() function (e.g. $this->Post->findAll('blog_id = $id AND language = "fr"'));) and are finding it doesn’t work, it’s because for variables to be parsed by PHP, they have to be enclosed in double quotes; otherwise, the above code will find all Posts that have blog_id equal to $id not whatever $id evaluates as. This may throw you off as all the examples in the cakePHP documentation make use of single quotes and no variables. So, in the above example, you would need
    $this->Post->findAll("blog_id = $id AND language = 'fr'"));, a small but important difference

For some more tips on cakePHP, see here.