cyprich.com

By

Stopping Spam on phpBB

I have forums that get thousand’s of page views per month. While the number of readers are increasing, so also are the spammers posting their ads. It got to the point that I had to switch the user registration to require the administrator to activate a new account. This can prevent the obvious spammers, i.e. those who use obscene names or add URL’s to unethical web sites.

The problem is that it’s hard to determine who is a legitimate user. Some people have crazy user names and e-mails so you can’t tell just by looking at what they enter.

After switching to admin authorization, the spam stopped but so did the user activity on the forums. I encountered this situation before and decided to go back to user authentication and delete spam as it was posted. I would spend about a half hour a day doing this, so it wasn’t such a great idea.

This blog uses Akismet to catch spam and it does so very effectively. Not one spam has been successfully posted here. I’ve tried various Akisment mods for phpBB but none of them worked. So the search for a solution continued.

After some time, I found a way to stop spam on Nadav Samet’s blog. His solution was very simple. When a new user registers on phpBB, they are asked a question that only a human can answer. Most spammers are actually automated scripts (or bots) scanning and posting messages. If you ask a question that requires intelligence, they will be unable to answer it.

The question that is asked is, what is 5+2? A spambot couldn’t answer that question. The script requires modifications of 2 files in phpBB. Its not very difficult finding the places to enter the code. The nice thing about this is that you can easily modify the question if spambots find a way to answer it.

This wouldn’t not stop a human spammer since most spam is automated. It needs to be because thousand’s of forums are being spammed. It would be too expensive to hire someone to spend time trying to bypass these tricky user registrations.

You can download the phpBB modification here.

By

Making .NET Faster with NGen

The one thing that concerns me about compiling a .NET application is that it doesn’t produce machine code (i.e. code that runs directly on a machine’s CPU). Instead, it creates code in the Microsoft Intermediary Language (MSIL). When you run the program, it use the just-in-time (JIT) compiler to produce native code.

When you run a .NET application, there is a slight delay before it starts. This is the JIT compiling it to machine code. Unfortunately, the native code isn’t stored permanently. It only stays in the running process’ memory space and disappears when the process stops running.

This is where an application in the .NET Framework that few people know about can be used. The Microsoft Native Image Generator (NGen) precompiles MSIL executables to platform specific native code before they are run. The application is then stored in the native image cache. The next time you run the program, it will run it from the cache and you won’t experience the .NET delay when an application starts.

NGen typically (but not always) improves the warm startup time of applications and occasionally the cold startup time. Warm startup time refers to the time it takes to start an application that was run recently (not between reboots). Cold startup time is the time it takes to run an application for the first time time since the computer was booted.

NGen.exe can be found in the .NET Framework folder in Windows, i.e. C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727. There is also a version of it in .NET 1.0. While there are many options for this application, you can run it by specifying a .NET program as a parameter, i.e.

ngen Test.exe

This will compile the MSIL Test.exe program to native code which then gets stored in the native image cache. The next time you run this program, it will be run from cache instead of getting compiled by JIT.

I should note that using NGen for .NET server applications won’t make much of a difference. There will only be a delay in start time the first time the application is run. Afterwards, it will run faster because it is already in memory. NGen works best with .NET client applications.