Adding a PECL extension to your PHP build environment

Last week I published winbuild.bat to setup PHP build environment on windows. In this blog I am covering how to add a PECL extension to the PHP build system. I will also show how to static link a PHP extension and how much performance benefit you can get by that.
Building a PECL extension
Let’s say you have the PHP build environment set in the folder c:\php\php_sdk\php_53_dev\vc9\x86\PHP_5_3. For adding PECL extension (e.g. WinCache) to the build process, first download source code of the extension in c:\php\php_sdk\php_53_dev\vc9\x86\pecl\ folder. You can use the following commands to do this.
pushd c:\php\php_sdk\php_53_dev\vc9\x86\
md pecl\wincache
cd pecl\wincache
tortoiseproc /command:checkout /path:. /url: /closeonend:1
Once you have downloaded the source code, follow steps below to add the extension to your build process.
1.       Open visual studio command prompt and run c:\php\php_sdk\bin\phpsdk_setvars.bat to set PHP build window.
2.       Go to c:\php\php_sdk\php_53_dev\vc9\x86\PHP_5_3 andrun buildconf.bat. This will make PHP build environment to create configure.js again with option to build WinCache.
3.       Run “configure –help” to confirm that –enable-wincache option is now present in configure options.
4.       Open config.nice.bat and add “–enable-wincache=shared” option to the configure command.
5.       Run config.nice.bat to generate new makefile.
6.       Run “nmake snap” to build full PHP or just use “nmake php_wincache.dll” to build only WinCache extension.
Running “nmake” command will create php_wincache.dll under c:\php\php_sdk\php_53_dev\vc9\x86\PHP_5_3\release folder. Steps above add PECL extension wincache to the PHP build system. You can add any other PECL extension to the build system by replacing wincache with that extension name. You can add multiple extensions by adding multiple switches to your configure command.
Static linking and performance comparison
Above steps used “–enable-wincache=shared” option in the configure command to add wincache to the build system. “=shared” tells the system to link the extension dynamically. Removing “=shared” from “–enable-wincache” or for that matter any configure switch will make that extension link statically. Performance with static linking is significantly better than when extensions are dynamically linked. If you know what PHP extensions you use, you can create a custom build with all those extensions statically linked. Let’s see how much performance improvement we get by statically linking wincache compared to when wincache is dynamically linked. I am using wordpress as the sample application.


Response time
Dynamic linking of wincache and mysql. All others as set by winbuild.bat.
68.05 requests/sec
726 ms
Static Linking of wincache and mysql extensions. All others as set by winbuild.bat.
72.12 requests/sec (5.98% better)
692 ms (4.68% better)
As you can see, just static linking of two extensions increased performance by ~5%. A custom build with needed PHP extensions statically linked will almost always perform better than official build from I hope that my last blog and this blog makes it easier to create custom PHP build on windows. I am experimenting with PGO builds these days and I will share my findings about that soon as well. Till then, CHAO.

3 thoughts on “Adding a PECL extension to your PHP build environment

  1. Pingback: PHP PGO build for maximum performance on Windows « Kanwaljeet Singla

  2. Pingback: Work items collected from Tek-X « Kanwaljeet Singla

  3. Thanks for this short simple tutorial, I spent the last two days trying to figure out how to get xdebug built with PHP 5.6.0-dev on Windows 7 with VS2012. This is SO simple, which it was in the PHP WIki, would have saved me at 10 hours. But it works now. Thanks again!

Leave a Reply

Your email address will not be published. Required fields are marked *