Installing and configuring memcached and PHP on Windows

After upgrading the CSFBL forums to vBulletin 4.0, I noticed that performance was slightly worse than in the previous version. A little searching revealed that vBulletin supports memcached (an in-memory distributed caching system). Since I’ve got RAM to spare, I figured this is worth a shot.

Unfortunately, getting memcached running on the server (Windows Server 2008 R2 64-bit) took a few tricks, and getting memached running through IIS/PHP was another. To help other people through the same process (and to remind myself in the future), I’ll share the installation and configuration steps that worked for me below.

Downloading and configuring memcached

The official distributions of memcached are written for Linux systems, so the first task is finding Windows binaries. The memcached project site, fortunately, has links to Windows binaries, which are hosted by NorthScale. Both 32-bit and 64-bit versions are available.

(Note that NorthScale also offers their own free distribution of memcached, but I was unable to get this to run on my system.)

Versions of memcached prior to 1.4.5 supported a command-line option that would register memcached as a Windows service (as in memcached -d install), but this option was removed in version 1.4.5. The simple alternative is to schedule memcached.exe to run using the Task Scheduler service (Windows 2008/Vista/7).

You can create a task to run memcached on system startup using the following command line:

schtasks /create /sc onstart /tn memcached /tr "'c:\dev\utils\memcached-amd64\memcached.exe' -m 128"

Note the -m 128 argument; this tells memcached to use up to 128MB of RAM. There are other command line arguments available; most useful aside from -m are -l (to specify what IP addresses to bind to) and -vv (to add verbose logging to the console, useful for testing).

Integrating memcached with PHP

In order for PHP to use memcached, you must download the PHP memcached library and add it as an extension to PHP.

PHP extensions can be downloaded from http://downloads.php.net/pierre. Many different extensions are in here; the one I used was php_memcache-5.2-nts-Win32-vc6-x86-20090408.zip. This extension matches two key requirements:

Getting the right version of the extension is important; download the thread-safe version, or the PHP 5.3 version, and it simply won’t work.

Once downloaded, take the php_memcache.dll and put it in the ext folder in your PHP directory (for me, c:\Program Files (x86)\PHP\ext). Then, open the php.ini file (in your PHP directory) and add the following line to the end:

extension=php_memcache.dll

Restart IIS (from the command line, type iisreset), and if you did everything right, memcached should now be available to PHP. If you want to check, you can create a phpinfo page; if php_memcache is listed in the output, the extension is registered correctly.

Other links

To find out more about PHP, memcached, and Windows, check out the following links.

More success converting from CommunityServer to vBulletin

Back in July, I wrote about my initial experiences converting from CommunityServer to vBulletin. At the time of that post, I was importing users, forums, and threads, but had issues importing posts. Well, I’m happy to say I’ve had more success since then.

Together with the help of Jerry (a member of the vBulletin team), we’ve improved the import scripts a number of ways. Prior to this effort, you were only able to import users, forums, threads, and posts. Now…

  • Performance has been improved by rewriting some SQL queries, and in some cases optimizing them for SQL 2005. (SQL 2000 compliant queries are available, but commented out in the code.)
  • Private messages are imported, however they are not threaded (by design; vBulletin doesn’t thread private messages).
  • Forum groups are imported as top-level forums, so your CommunityServer group/forum structure is preserved.
  • SQL scripts are available to clean up post formatting differences between CS and vB.
  • Not a fix, but an important note: If you have lots of posts, you definitely need to increase your timeout periods in your php.ini. I set mine to 600 seconds before things started working reliably importing posts.

Continue reading

Converting from CommunityServer to vBulletin

I’ve been using CommunityServer to power the forums at CSFBL for a few years now, with mixed results. The version I am running (2.1) is a bit buggy and a poor performer in some respects, but it is serviceable. Still, with hundreds of thousands of posts, I really need something more reliable.

The obvious choice was to upgrade to CommunityServer 2008, but problems with the upgrade script and stickershock at the new price tag pretty much put this right out of contention. I went out and bought a license for vBulletin — one of the most widely-used bulletin board products available — for $160, about 1/50th the price I’d pay to upgrade CommunityServer.

vBulletin offers some support for converting from CommuntyServer via their Impex utility. Unfortunately, the current implementation they had was quirky and unreliable… but vBulletin gives you the source code (everything, including the import/export scripts for dozens of other forums), so I began to tinker.

Continue reading