Spidermonkey in PECL


Today I finally released spidermonkey on PECL, you can find it here: http://pecl.php.net/package/spidermonkey/

The whole thing should work fine, I’m already working on several optimisations thanks to jorendorff from Mozilla on IRC. The next thing is to provide better error report, compilation/decompilation of scripts and more default functions for a bunch of things like Iterators and the like.

The last thing I added is a bunch of function applied to streams, here is an exemple:

/* create context */
$ctx = new JSContext();
/* provide fopen/fclose functions */
$ctx->registerFunction('fopen');
$ctx->registerFunction('fclose');
/* for output */
$ctx->registerFunction('printf');

Then in Javascript:

/* open file */
fd = fopen('somefile.txt', 'r')
while (line = fd.getline()) {
  printf("%s\n", line)
}
fclose(fd)

Or

/* open file */
fd = fopen('somefile.txt', 'w')
/* here fd.SEEK_SET is the default value and is optional */
fd.seek(1024, fd.SEEK_SET)
fd.write("some text here :D")
fclose(fd)

, , , , ,

  1. #1 by Jonathan - February 24th, 2009 at 20:31

    Congrats !

  2. #2 by Christophe - February 25th, 2009 at 09:16

    Is there any plan to use this server-side Javascript syntax in the browser ? Will you process on the server the script tags marked with runat=”server” ?

  3. #3 by Christophe Robin - February 25th, 2009 at 10:11

    No there is no plan like this yet, what I’m providing is a tool allowing you to run Javascript – There are a lot of ways to parse those kind of tags so I think it’s better for the user to implement it himself using either a template system, an output filter or whatever you want. That way you’ll get a lot more control.

  4. #4 by Christophe - February 25th, 2009 at 10:20

    Makes sense, thanks.

  5. #5 by Oliver - February 26th, 2009 at 12:31

    Congrats. Hopefully have an excuse to use your extension soon.

  6. #6 by Christophe Robin - February 26th, 2009 at 23:07

    Tomorrow I’ll release version 0.1.1 which should remove a bug on NULL PHP values and makes several optimisations coming with revision 47 on the SVN

  7. #7 by Dima - May 8th, 2009 at 10:23

    Hi, I tried to install this extension, but I found the problem:

    yums:/# pecl search spidermonkey
    Retrieving data…0%MATCHED PACKAGES, CHANNEL PECL.PHP.NET:
    =======================================
    PACKAGE STABLE/(LATEST) LOCAL
    spidermonkey 0.1.2 (beta) JavaScript engine for PHP
    yums:/# pecl install spidermonkey
    Failed to download pecl/spidermonkey within preferred state “stable”, latest release is version 0.1.2, stability “beta”, use “channel://pecl.php.net/spidermonkey-0.1.2″ to install
    Cannot initialize ‘channel://pecl.php.net/spidermonkey’, invalid or missing package file
    Package “channel://pecl.php.net/spidermonkey” is not valid
    install failed
    yums:/# pecl channel-add channel://pecl.php.net/spidermonkey-0.1.2
    channel-add: Cannot open “channel://pecl.php.net/spidermonkey-0.1.2″ (Cannot download nonjavascript:document.tcommentform.submit();-http URL “channel://pecl.php.net/spidermonkey-0.1.2″)
    yums:/#

  8. #8 by Christophe Robin - May 8th, 2009 at 11:59

    I’d suggest you to build the latest SVN revision, just check how to do at the end of: http://www.bombstrike.org/2009/02/bringing-javascript-to-the-server/
    Also, make sure you have: PHP 5.3 ( beta or RC ), spidermonkey 1.7+

  9. #9 by martin - May 21st, 2009 at 00:45

    This looks very promising and is just what I am looking for for a project. Unfortunately getting it to run proves to be the most excruciating task. I’ve finally got the latest php snapshot running but this disables CLI and subsequently pear and pecl. Anyway, I managed to restore that functionality but when i try to install the package i run into this error:

    checking whether to enable spidermonkey support… yes, shared
    configure: error: jsapi.h not found. Please reinstall libjs.
    ERROR: `/etc/php5/temp/spidermonkey/configure’ failed

    i have no idea where to get “jslib”. Part of what package-system or package is that? What I could find is either the old mozilla “jslib” or the rather new “jslibs” project. What do I have to do to get past this point (on to the next fatal error?)

    thank you very much for the great extension and I’d be too happy actually using it!

  10. #10 by Christophe Robin - May 21st, 2009 at 15:14

    Which distribution are you using ? Depending on the distro, there should be package named libjs or spidermonkey, if not you’ll need to get this file: http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz and build/install it on your system manually.

  11. #11 by martin - May 21st, 2009 at 19:36

    Thanks for the reply! I am using Ubuntu 8.10. I installed spidermonkey from the repository. There also are several packages that begin with libjs but most of them appear to be just clientside js frameworks or joystick drivers.

    I just tried that mozilla link but it refused to compile.

    The install still fails at the same position. My js-cli (that came with spidermonkey i presume) version is JavaScript-C 1.7.0 2007-10-03.

    Is there may a static binary i could use to test?

  12. #12 by John - June 6th, 2009 at 17:51

    Great work on this extension. Very useful to have, although we can’t use it because of the need for PHP 5.3 beta/RC. Do you know why that’s required and if there’s any way we can make this work with 5.2.x?

  13. #13 by saaadel - August 11th, 2009 at 09:41

    Simple trick with this module code and ….
    http://saaadel.com/phpinfo.php

    spidermonkey 0.1.2 work at PHP Version 5.2.6-3ubuntu4.1

  14. #14 by wojta - September 3rd, 2009 at 11:47

    I have added this bug with PHP compiled as Apache2 module:
    http://pecl.php.net/bugs/bug.php?id=16641

  15. #15 by Ionut G. Stan - December 9th, 2009 at 23:59

    Hi Christophe,

    Great work on this extension! I have a couple of feature requests (to come) and a bug report (unfortunately):

    http://pecl.php.net/bugs/bug.php?id=16967

    Alas, my C skills are almost null, otherwise I’d have tried to help you on this. Maybe if you could give me at least some pointers on where to look for solving this…

(will not be published)
  1. No trackbacks yet.