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).
PHP: v8.js
31–40 of 43 posts
Re: PHP: v8.js
#32Therefore 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
#33Re: PHP: v8.js
#34Re: PHP: v8.js
#35This 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?
Re: PHP: v8.js
#36Earlier 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.
Re: PHP: v8.js
#37Can 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?
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
#38Re: PHP: v8.js
#39Earlier 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!
...which fulfills the requirement of "executing some JS code even if JS is disabled in browser".Re: PHP: v8.js
#40Earlier 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".