Main | February 2010 »

January 2010

Jan 28, 2010

GB18030 support for PHP5.3

GB18030 is the new Chinese standard character encoding that every software in China needs to support.  However, the current PHP5.3 does not support it.

This patch adds GB18030 support to libmbfl, a unicode string library embedded and used in PHP.  The patch applies cleanly to PHP-5.3.1.

Download: libmbfl_gb18030.patch


Jan 27, 2010

Fix for mod_fastcgi Unclean Exit

mod_fastcgi is an Apache module to run FastCGI servers (including PHP).

On exit, mod_fastcgi tries to terminate all running servers started by itself, but leaves one server (one PHP process) on Windows.  This is because the surviving PHP process keeps listening a new request even after the exit event (not a signal on Windows) has been delivered and processed by another thread.

This patch fixes this bug by explicitly using TerminateProcess() for surviving FastCGI servers.  The patch applies cleanly to mod_fastcgi-SNAP-0910052142.

Download: fcgi_kill.patch


PHP Native LDAP Patch for Windows

Current version of PHP uses OpenLDAP client library on Windows, even though OpenLDAP has dropped Windows support.

We made a patch to let PHP use Windows native LDAP API instead of OpenLDAP. This patch applies cleanly to PHP version 5.3.1.

Download: php_ldap.patch


Jan 21, 2010

PHP Syslog Patch for Windows

WARNING: This patch is only applicable when your PHP's mbstring.internal_encoding is UTF-8.

The current implementation of PHP's syslog() function cannot properly send UTF-8 strings to eventlog because it uses ReportEventA().  This patch translates UTF-8 internal encoding into WCHAR (UTF-16) and sends it using ReportEventW() to avoid string corruptions.

In addition, the current implementation maps LOG_ERR severity to eventlog's warning level, which I think misguided.  This patch changes the mapping of LOG_ERR to eventlog's error.

Download: php_syslog.patch

YAMAMOTO Hirotaka (tnnrg)

Cyrus SASL Static Plugin Patch

Cyrus SASL library is a widely used SASL implementation.  The library can load SASL mechanisms as plugin DLLs.  For us, such dynamic loading is no good because our bundled Cyrus SASL library should use statically embedded mechanisms only.

This patch adds a configure option to disable such dynamic loading of mechanisms.
The patch should be applied to cyrus-sasl-2.1.24rc1.

Download the patch: 1-static-plugin.patch

The original tarball is available at official site:

The following contents are the detail description of the patch.

* Changes

* Added --enable-staticplugin option for configure script.
  for nmake build on Windows.
* Fixed to delete several build warnings.

* Status

* Verified build target:
  Linux 32bit/64bit and Windows 32bit/64bit.

  Test environment:
    Windows: Windows server 2008 standard SP1 64bit
             with Visual Studio 2008 SP
    Linux:   CentOS 5.3 64bit with gcc-4.3.4

* Verified plugins:
  anonymous, plain, login, cram-md5, digest-md5, ntlm.

* How to build

* Build on Linux

1. Extract source archive and apply the patch files.

  > tar xzf cyrus-sasl-2.1.24rc1.tar.gz
  > cd cyrus-sasl.2.1.24
  > patch -p1 < ../1-static-plugin-autotools.patch
  > patch -p1 < ../2-static-plugin-nmake.patch
  > patch -p1 < ../3-deleting-build-warnings.patch

2. Rebuild configure script.

  On the top directory of source tree:
  > rm -rf autom4te.cache
  > aclocal -I cmulocal -I config
  > autoheader
  > automake -c -f -a
  > autoconf
  > cd saslauthd
  > aclocal -I ../cmulocal -I ../config
  > autoheader
  > automake -c -f -a
  > autoconf
  > cd ..

3. Run configure script to create Makefile

  > ./configure --enable-staticplugin

4. Build the library and plugins.

  > make

* Build on Windows (with nmake)

1. Extract source archive and apply the patch files.

  Do the equivalent operation as the linux build.

2. Open Visual Studio Command Line Prompt

  Run the following command to select your required compiler:
  for 32bit build,
  > "%VCINSTALLDIR%\vcvarsall.bat" x86
  for 64bit build,
  > "%VCINSTALLDIR%\vcvarsall.bat" amd64

3. Build the library and plugins.

  On the top directory of source tree:
  > nmake -f NTMakefile STATIC_PLUGIN=yes

  You can specify SASLDB=1 SASL_DB_PATH=c:\\\\sasl\\\\sasldb options
  to enable sasldb plugin with berkeley db.
  You need also DB_LIBPATH, DB_INCLUDE, and DB_LIB options.
  The plugin will be also statically linked
  with STATIC_PLUGIN=yes option.


Jan 20, 2010

FastCGI development kit patches to support WIN64 with several fixes

These patches enable windows 64bit library build of FastCGI Development Kit with Visual Studio 2008 for current snapshot (2.4.1-SNAP-0910052249).

Original tarball is available on the official site:

Each patch description:

* Fixed functions to support both 32/64 bit build.
  AlignInt8(), AlignPtr8().
  This modification is essential for Windows 64bit build.

* Fixed socklen_t detection failure problem in configure script
  for Linux.

* Fixed for gcc-4.4 build on Linux.

* Converted Win32/*.{dsw,dsp} files to Win32/*.{sln,vcproj} files
  (Visual Studio 2008 solution/project files) and
  added platform "x64" for 64bit build.
* Removed almost all build warnings on Visual Studio 2008.
  with PreprocessorDefinitions:

* Fixed type size problem (pointer, size_t, etc.)
  to support both 32/64 bit build
  using intptr_t, uintptr_t, etc.
* Fixed to check range of each numeric variable with ASSERT()
  before using type cast for demotion(narrowing).
* Replaced several standard functions to recommended ones.
  getpid() --> _getpid(), and so on.
* Removed almost all build warnings on Linux.

Current status:

* Tested the patches on Windows Server 2008 SP1 (64bit).
  with apache httpd 2.2.14 (32bit) and mod_fastcgi-SNAP-0910052141.
  Both 32/64 bit sample executables are working.
  We could not build and test two samples: threaded and log-dump.
* Tested the patches on CentOS 5.4 (64bit) with gcc-4.3.4.
  For 32bit build, we used gcc -m32 option.
  Both 32/64 bit sample executables are working except log-dump.
  We could not find out the usage of log-dump
  so that we could not test it.

How to build:

1. For Windows

1-1. Extract fastcgi-2.4.1-SNAP-0910052249.tar.gz.

> tar xzf fastcgi-2.4.1-SNAP-0910052249.tar.gz
1-2. Apply patch files.

> cd fastcgi-2.4.1-SNAP-0910052249
> patch -p1 < ../1-align-x64.patch
> patch -p1 < ../2-socklen.patch
> patch -p1 < ../3-gcc44.patch
> patch -p1 < ../4-vc9.patch
> patch -p1 < ../5-build-warnings.patch
1-3. Open fastcgi-2.4.0/Win32/FastCGI.sln with Visual Studio 2008 and build.

Debug and Release build on Win32 and x64 are supported.

Build with 'nmake' is not supported, since we could not find out
suitable project converter and we can use 'devenv' command line instead.

2. For Linux

2-1. Do the same process as (1-1).
2-2. Do the same process as (1-2).

2-3. Remake configure script.

> libtoolize -c -f
> aclocal
> autoheader
> automake -a -c -f
> autoconf
2-4. Configure and make

> ./configure
> make
> make install
If you need, NDEBUG preprocessor definition should be specified
to eliminate ASSERT check for release build.


Spidermonkey PHP Extension patches

There are three patches to enhance or fix bugs of Spidermonkey PHP Extension.
This patches are for spidermonkey-0.1.3.tgz from the official web site:

The patches must be applied in the following order.

(1) spidermonkey-windows.patch
Support windows build of the extension.
Specify --with-spidermonkey=${SPIDERMONKEY_INSTALLED_DIRECTORY} as configure option.
Currently shared library build is not supported.

(2) spidermonkey-line-number.patch
Print not only line number but also specified string text when an error occurs in interpreting javascript code. Specify a prefer string to the second argument of evaluateScript() function. It will help your debug javascript code in PHP. Of course it can be omitted.

(3) spidermonkey-empty-string.patch
This fixes PECL Bug #16876.


About This Blog


I am CTO of Cybozu Inc., a leading groupware vendor in Japan.

We are using a lot of open source softwares in our products & services, and have contributed a lot of bug fixes and enhancements to communities.  However, we have not opened patches for our specific purposes, or some communities are so closed and inactive that they cannot review or merge our patches.

In this blog, we will release miscellaneous patches for open source softwares, hoping somebody would find them useful.  We may release our software as OSS through this blog, too.

Best regards,

YAMAMOTO Hirotaka (tnnrg)