Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are use cases for V8 in PHP?

PHP has embedded V8 JavaScript engine, http://www.php.net/manual/en/book.v8js.php. I was wondering what are possible use cases, esp. considering that PHP is synchronous and JavaScript is asynchronous.

like image 814
Gajus Avatar asked Aug 07 '13 09:08

Gajus


2 Answers

A powerful feature of this extension is that the same code can be used both client and server side, reusing implementations of the same code in PHP for server side and js client side.

A possible use case is for providing server and client side validation using the same JS code. Client side, the code would be run in the browser, and server side it's executed using V8JS.

Other potential uses could be templates or any other business logic that's needed both client and server side.

It seems like you'll still be in uncharted territory here, though. I haven't seen any libraries use V8JS for anything like this.

like image 136
Dave Lancea Avatar answered Sep 30 '22 02:09

Dave Lancea


One of the ways I am using JS integration within PHP is to provide a simple manner for end users to safely execute user-supplied code (a.k.a. scripts) within a PHP-based app. With the implicit isolation, one can limit the inputs and functions available to protect both user privacy and system security while allowing a wide range of user-defined scripted actions within the server context.

I must admit that seeing executable javascript code in database records is a bit unnerving at times! You do get over it though. :)

like image 21
J Marshall Presnell Avatar answered Sep 30 '22 02:09

J Marshall Presnell