So then I looked at Mozilla and wondered if their Spidermonkey engine could be used. I didn't have to look much further to see that there was already a fantastic PHP PECL package written by Christophe Robin that wraps the Mozilla Spidermonkey engine. Theoretically a perfect solution, giving speed, efficiency and reliablity - the only hurdle was to get it built on Windows - it wasn't a piece of cake, but worth the effort, and nothing compared to the effort of the programmers who wrote the code.
I am posting the binaries here so that others can get up and running instantly. The instructions on how to build these follow:
- all_php_builds.zip contains php_spidermonkey.dll for Windows, for PHP 5.5 (32 and 64-bit), 5.4 and 5.3.
- Useful links:
- For builds to do with PHP, I use this VC9 SDK from Microsoft: http://www.microsoft.com/en-us/download/details.aspx?id=3138
- Get and build Spidermonkey 1.8.5 from here: https://developer.mozilla.org/En/SpiderMonkey/Build_Documentation.
- Get the source code - near the top of the page is a link to it, or you can get it from here: http://ftp.mozilla.org/pub/mozilla.org/js/.
- Get the build tools for Windows - near the top of the page is a list of platforms - click on Windows, then about half way down the page is a link to the Mozilla build tools entitled "Download the current MozillaBuild package".
- Once the build tools are installed, run "
start-msvc9.bat", as documented on the Windows page. It opens a Mozilla command window (a unix bash simulation).
- Go back to the Build Documentation and follow the instructions for "Easy Build".
- Building php_spidermonkey is a bit more tricky. Get the original source code here: http://pecl.php.net/package/spidermonkey/1.0.0. It does not build on Windows VC9 at all without adjustment, but the code is sound - it's just minor technicalities and looks worse than it is.You need a working PHP build environment to build the extension. This won't make any sense unless you know how to build PHP extensions - these instructions work with my modified source code...:
- Create a spidermonkey folder in php extensions, and copy this (modified) source code into it: php_spidermonkey source (submitted to https://github.com/christopherobin/php-spidermonkey)
- Create sub-folder "php54dev\vc9\x86\deps\include\js", and copy all of the .h files from the spidermonkey api folder "js\src" into it.
- Add "--with-spidermonkey=shared" to your PHP configure command.
- Build PHP.