Update 19 June 2014 - the latest builds of php_spidermonkey for Windows are contained in this zip: all_php_builds.zip. I reported a few days ago that the PHP 5.5 TS build did not work - as of 19 June 2014 it works. PHP 5.5 includes 64-bit versions in the x64 folder of the zip file.
I needed to evaluate a web browser's PAC (proxy auto config) file exactly the way a browser would, by executing the Javascript function FindProxyForURL (see here for a good guide). The browser uses its Javascript engine, so to simulate it, I wanted to run Javascript inside PHP (an example is here in another post).
On the web there were some solutions for Javascript engines, written in PHP, such as J4P5 (http://j4p5.sourceforge.net/) and PHPJS (http://include-once.org/p/phpjs/); the problem is that these solutions, however impressive, are not the real thing. There will be nagging worries about reliability and speed.
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:
- Download:
- 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)
- Get the recently built javascript static library "js_static.lib" located in "js\src\dist\lib", copy it to PHP build environment folder "php54dev\vc9\x86\deps\include\lib", and rename it "js32.lib"
- 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.
Hi - I was all excited by this post until I tried to download the dll. Then I discovered that the link to the compiled dll is broken. I'm afraid the steps you describe for the build are way outside my level of competence: would it be possible to make the dll available somewhere else?
ReplyDeleteMany thanks
Link seemed ok when I tried it - it might have been a temporary glitch on Skydrive - the link tries to open in a new window if it's any help in solving what went wrong.
DeleteHi, sorry the link didn't work, I'll have a look asap. All my downloads are on the same page, so if you go to the unofficial sqlsrv page, click the download on that page and it will take you to the download for php_spidermonkey.
ReplyDeleteSorry, I'll try from home, I just realised that for some reason I was blocked by our proxy service at work
ReplyDeleteSame here, I should have thought of that. I waste half my time at work browsing the web from my phone to stop them blocking access and intercepting ssl connections.
DeleteYup, that was the issue. I didn't recognise it at first because (presumably something to do with the tinyURL) it didn't show up our normal "you have been blocked" page but just a DNS error. Anyway, now I'll have some fun trying to play with it!
ReplyDeleteHi!
ReplyDeleteHow is the dll instalation in wamp?
Thank You! ;)
Put the DLL in your php extensions folder and add it to php.ini.
DeleteFor example if you were using php 5.4 you would need php_spidermonkey_54_ts.dll
Thanks for the unofficial driver for sqlsrv. Microsft neegd to load the correct dll for ease of setting up SQL for PHP.
ReplyDeleteC:\Users\BILL>php -v
PHP Warning: PHP Startup: Unable to load dynamic library 'ext\php_sqlsrv_56_ts.
dll' - %1 is not a valid Win32 application.
in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'ext\php_pdo_sqlsrv_56
_ts.dll' - %1 is not a valid Win32 application.
in Unknown on line 0
PHP 5.6.19 (cli) (built: Mar 2 2016 20:09:42)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
Regards
kntbill@gmial.com