Fishtrap

php and other stuff I know

Compiling PECL extensions on Windows timezonedb

| 1 Comment

By Renee Comet (photographer) (National Cancer Institute: page, image)[see page for license], via Wikimedia Commons

By Renee Comet (photographer)

A client had a need for up to date timezone data in PHP so I pointed them at http://pecl.php.net/package/timezonedb. Unfortuantely the client was using windows as the server environment and there is no windows build of this extension.

 

So I thought I’d have a go at building a PECL extension on Windows. The great thing about windows is that a dynamic link library built on one installation should work on any windows installation provided the same threading option and compiler is used.

If you do a google search on compiling PECl on windows you’ll get a mirad of different instructions. Many of these are confusing and don’t work for all extensions. You will also find many people saying that it is just too difficult to bother with but I found it surprisingly easy. The steps which seemed to work best for me were in Sala Goleman’ excellent book Extending and Embedding PHP which is possibly the best book about PHP and easily the best book on PHP internals. I would recommend buying the book but it also seems to be available here.

The steps are better described in the book but just for my own memory:

  1. Download the php source code for your version of PHP. Place it a directory close to the root like C:/phpdev do not put in a directory where spaces appear in the full path e.g. C:/Documents and Settings/Admin/phpdev as some later used batch scripts will have problems if you do
  2. Download the pecl extension code and pop it in the ext directory along side the other extensions
  3. Download Visual Studio C++ 2008 Express (Do not be tempted by the 2010 version the binary version of PHP was compiled with 2008 or VC9 and the compiler versions must match)
  4. open up a Visual Studio 2008 command prompt
  5. Change directory into the bin directory inside the one it placed you in
  6. run
    vcvars32.bat

  7. change directory into the base of the php source
  8. run
    nmake clean

    to clean up all previous builds

  9. run
    buildconf.bat

  10. run
    configure --help 

    and check that one of the options is that defined in the conf.w32 e.g. --enable-timezonedb

  11. cscript /nologo configure.js --enable-timezonedb=shared --without-mysqlnd --disable-zts

  12. nmake php_timezonedb.dll

Et voila! you should have a working dll in the Release directory of you source. Copy it to you PHP ext directory and enable in the php.ini and you should see it installed in the output of phpinfo();

The version I built is here timezonedb-2010-15-win32-nts-VC9

One Comment

  1. Now recompiled for timezonedb 2010.15 released 1/11/2010

Leave a Reply

Required fields are marked *.

*