Live data from Hacker News

PHP: v8.js

php.net

31–40 of 43 posts

Re: PHP: v8.js

#31
For a nicer looking wrapper around V8 in a dynamic language, see http://code.google.com/p/pyv8/ -- here your class instances become the namespaces accessible to your JS code and objects are nicely converted back and forth.

I experimented with (py) V8 as an engine for executing certain scripts from Python, but found there was a relatively cost to entering the interpreter. I was also missing a way to pass around buffers and not converting everything to unicode strings (maybe if I could wrap the ByteArray type).

Re: PHP: v8.js

#32
We have the use case to render the same mustache [1] templates on the server side (PHP) and on the client side (JS). Problem here is that the template helper view functions have to be written in two languages, PHP and javascript.

Therefore we started two weeks ago to evaluate javascript rendering of mustache templates from inside PHP. First we tried the spidermonkey extension, but had some issues with it. Currently we are using v8js on mac and ubuntu. Works like a charm so far, and we have to write template functions only once.

Now we can use the same mustache templates AND helper functions from within PHP and client side javascript. Even compiled hogan [2] templates work. The templates and javascript files are stored in the PHP APC cache to avoid disk seeks.

So far we are very happy with the results. Here is some php pseudo code how it works with mustache:

pseudo-php-example: \V8Js::registerExtension("mustache", apc_fetch("hogan.js-content")); $v8 = new \V8Js('ContextName', array(), $extensions); $v8->view = array("stuff" => "available in the js template"); $v8->view = array("partialName" => apc_fetch("partialTemplateContent")) $v8->template = "{{stuff}}"

$script .= 'Mustache.render(PHP.template, PHP.view, PHP.partials);'; $renderedTemplate = $v8>executeString($script); echo $renderedTemplate; // prints available in the js template

I recommend checking the v8js samples [3].

[1] http://mustache.github.com/ [2] http://twitter.github.com/hogan.js/ [3] http://svn.php.net/viewvc/pecl/v8js/trunk/samples/

Re: PHP: v8.js

#35
post #29

This is interesting, and I saw the one Example (Hello World) they have on the site. So I guess my question is, why? What's a real use case example of why'd I want this? PHP isn't syntactically more tragic than JS. JS doesn't have so many more libraries than PHP already has? I can't see why someone would use this? Maybe to hook into GWT librarieS?

The only "why" that I've been able to surmise is for people using PHP to scrape/interpret content from existing webpages. But I only make that assumption looking at the itches that Jani (the lead behind the PHP v8js) has been scratching recently: http://pecl.php.net/~jani/patches/

Re: PHP: v8.js

#36

Earlier quoted context omitted.

Can you elaborate?

Let's see. Practically - a web templating language with weakly-typed bolt-on OO 'featurettes' now has an embeddable, weakly-typed, object-oriented scripting language. Hello run-time heisenbugs that can NEVER be unit tested nor debugged. Anecdotally - let's face it; there is no shortage of crappy php and javascript out there. This is an open invitation to merge the two into one extraordinary megaclusterfark.

Yes, but it could still be legitimately useful. Show me a powerful technology and I'll tell you how it can be misused, but that won't invalidate its potential usefulness.

Re: PHP: v8.js

#37
post #9

Can anybody give some use cases for this? Would this allow me to use JS libraries (made for node for instance) in my PHP code, or is there something else I could do with this?

most libs that work with node wouldn't work with this since they're not going to support the node module loading system. You could create some kind of polyfill, but what's the point?

Probably easier to just php `exec()` a node script that does what you want. In fact, if you're considering using this, you'd be better off using node since it will almost undoubtedly perform better.

Re: PHP: v8.js

#38
Great, just as I'm moving away from PHP and diving into Ruby (I've fallen for it's OO charm), they have to release such a wonderful engine. This is amazing though, well done.

Re: PHP: v8.js

#39
post #24

Earlier quoted context omitted.

yes but that would require server to know that which again requires some sort of ajax which cannot happen because js is disabled!

apparently I have to spell it out to the downvoter...

    
    
...which fulfills the requirement of "executing some JS code even if JS is disabled in browser".

Re: PHP: v8.js

#40

Earlier quoted context omitted.

apparently I have to spell it out to the downvoter... ...which fulfills the requirement of "executing some JS code even if JS is disabled in browser".

yes, that seems correct, also just to make it clear, i can't even down vote yet :P so it wasn't me :)
Post reply on HN