Skip to content
Interface for using spidermonkey in PHP
Find file
Latest commit 95144b4 @christopherobin Merge pull request #9 from christopherobin/moz24
Ported the extension to support the latest versions of Spidermonkey


Interface for using spidermonkey in PHP


Make sure you have a recent version of spidermonkey installed (JSAPI 17 or more). Then checkout that project, and inside the folder run:


You should find the file in the modules folder.



// a JSContext is where your code run, each context has it's own scope
$js = new JSContext();

// you can register functions to be made availables in js
// by default it makes it available as the same name, you can change that by doing
$js->registerFunction('printf', 'another_name');

// you can also register PHP classes for access, doing so will make that class
// available for instanciation in javascript and all methods available

// then to run you actual script, just do the following
try {
    // script is a string containing javascript code
} catch (Exception $e) {
    // do something with the exception
Something went wrong with that request. Please try again.