All Projects → phpv8 → Php V8

phpv8 / Php V8

Licence: mit
PHP extension for V8 JavaScript engine

Projects that are alternatives of or similar to Php V8

V8js
V8 Javascript Engine for PHP — This PHP extension embeds the Google V8 Javascript Engine
Stars: ✭ 1,659 (+742.13%)
Mutual labels:  php-extension, v8
Pht
A new threading extension for PHP
Stars: ✭ 175 (-11.17%)
Mutual labels:  php-extension
Php Akm
Ahocorasick keyword match.
Stars: ✭ 116 (-41.12%)
Mutual labels:  php-extension
Rusty v8
V8 javascript bindings for Rust
Stars: ✭ 2,022 (+926.4%)
Mutual labels:  v8
Cphalcon
High performance, full-stack PHP framework delivered as a C extension.
Stars: ✭ 10,534 (+5247.21%)
Mutual labels:  php-extension
Jsc
A JavaScript compiler written in TypeScript targeting C++/V8
Stars: ✭ 135 (-31.47%)
Mutual labels:  v8
Msphpsql
Microsoft Drivers for PHP for SQL Server
Stars: ✭ 1,570 (+696.95%)
Mutual labels:  php-extension
Unreal.js Core
Unreal.js plugin submodule
Stars: ✭ 189 (-4.06%)
Mutual labels:  v8
Discovery
Discoveries on Sustainable Loading research
Stars: ✭ 174 (-11.68%)
Mutual labels:  v8
Ycdatabase
The lightest php database framework written in c language, built in php extension, for mysql
Stars: ✭ 130 (-34.01%)
Mutual labels:  php-extension
Php Zephir Parser
The Zephir Parser delivered as a C extension for the PHP language.
Stars: ✭ 129 (-34.52%)
Mutual labels:  php-extension
Core
Server core components which are a part of ONLYOFFICE Document Server
Stars: ✭ 152 (-22.84%)
Mutual labels:  v8
Llvm Node
Node LLVM 4.0+ Bindings
Stars: ✭ 127 (-35.53%)
Mutual labels:  v8
Php Rdkafka
Production-ready, stable Kafka client for PHP
Stars: ✭ 1,703 (+764.47%)
Mutual labels:  php-extension
V8
✔️8️⃣ 分析V8和周边技术、并且着手代码的优化
Stars: ✭ 179 (-9.14%)
Mutual labels:  v8
Bacardi
Bacardi project is an effort to provide multi-language binding for Node.js native layer.
Stars: ✭ 115 (-41.62%)
Mutual labels:  v8
V8dotnet
A fairly non-abstracted wrapper for Google's V8 JavaScript engine.
Stars: ✭ 133 (-32.49%)
Mutual labels:  v8
Php Psr
PHP extension providing the accepted PSR interfaces
Stars: ✭ 189 (-4.06%)
Mutual labels:  php-extension
Easy Monitor
企业级 Node.js 应用性能监控与线上故障定位解决方案
Stars: ✭ 2,451 (+1144.16%)
Mutual labels:  v8
V8 Natives
Access v8 Engine Natives easily in Chrome & Node
Stars: ✭ 161 (-18.27%)
Mutual labels:  v8

php-v8

PHP extension for V8 JavaScript engine

Build Status GitHub license Docs

This extension requires PHP >= 7.2. Last version that supports PHP 7.1 is v0.2.2 and for PHP 7.0 is v0.1.9.

This extension is still under heavy development and its public API may change without any warning. Use at your own risk.

Work in progress documentation could be found at https://php-v8.readthedocs.io. You can also use tests and stubs as reference.

Why (aka Rationale)

This tool solves following domain problems:

  • execute arbitrary untrusted code from user;
  • provide restricted/experimental api to end-user;
  • allow to use that with scripting/DSL language;
  • limit execution time and used memory;
  • use common language that is familiar to large audience;
  • be well-maintainable and mature.

By accident (not by design) this tool could also be used to:

  • render React/Vue/Angular components in PHP;
  • implement node.js in PHP;
  • increase the number of "why", "why not just <...>" questions.

If you have any other use, feels free to share

About

php-v8 is a PHP 7.x extension that brings V8 JavaScript engine API to PHP with some abstraction in mind and provides an accurate native V8 C++ API implementation available from PHP.

Key features:

  • provides up-to-date JavaScript engine with recent ECMA features supported;
  • accurate native V8 C++ API implementation available from PHP;
  • solid experience between native V8 C++ API and V8 API in PHP;
  • no magic; no assumptions;
  • does what it is asked to do;
  • hides complexity with isolates and contexts scope management under the hood;
  • provides a both-way interaction with PHP and V8 objects, arrays and functions;
  • execution time and memory limits;
  • multiple isolates and contexts at the same time;
  • it works.

With this extension almost everything that the native V8 C++ API provides can be used. It provides a way to pass PHP scalars, objects and functions to the V8 runtime and specify interactions with passed values (objects and functions only, as scalars become js scalars too). While specific functionality will be done in PHP userland rather than in this C/C++ extension, it lets you get into V8 hacking faster, reduces time costs and gives you a more maintainable solution. And it doesn't make any assumptions for you, so you stay in control, it does exactly what you ask it to do.

With php-v8 you can even implement nodejs in PHP. Not sure whether anyone should/will do this anyway, but it's doable.

Demo

Here is a Hello World from V8 Getting Started developers guide page implemented in PHP with php-v8:

<?php
$isolate = new \V8\Isolate();
$context = new \V8\Context($isolate);
$source = new \V8\StringValue($isolate, "'Hello' + ', World!'");

$script = new \V8\Script($context, $source);
$result = $script->run($context);

echo $result->value(), PHP_EOL;

which will output Hello, World!. See how it's shorter and more readable than that C++ version? And it also doesn't limit you from V8 API utilizing to implement more amazing stuff.

Quick start

You can try php-v8 in phpv8/php-v8: docker run -it phpv8/php-v8 bash -c "php test.php"

Stub files

If you are also using Composer, it is recommended to add the php-v8-stub package as a dev-mode requirement. It provides skeleton definitions and annotations to enable support for auto-completion in your IDE and other code-analysis tools.

composer require --dev phpv8/php-v8-stubs

High-level wrapper library

There is phpv8/js-sandbox library that provides high-level abstraction on top of php-v8 extension and makes embedding JavaScript in PHP easier.

Installation

Requirements

V8

You will need a recent v8 Google JavaScript engine version installed. At this time v8 >= 6.6.313 required.

PHP

This extension requires PHP >= 7.2. Last version that supports PHP 7.1 is v0.2.2 and for PHP 7.0 is v0.1.9.

OS

This extension works and tested on x64 Linux and macOS. As of written it is Ubuntu 16.04 LTS Xenial Xerus, amd64 and macOS 10.12.5. Windows is not supported at this time.

Quick guide

Ubuntu

$ sudo add-apt-repository -y ppa:ondrej/php
$ sudo add-apt-repository -y ppa:pinepain/php
$ sudo apt-get update -y
$ sudo apt-get install -y php7.2 php-v8
$ php --ri v8

While pinepain/php PPA targets to contain all necessary extensions with dependencies, you may find pinepain/libv8 and pinepain/php standalone PPAs useful.

OS X (homebrew)

$ brew tap homebrew/dupes
$ brew tap homebrew/php
$ brew tap phpv8/tap
$ brew install php72 php72-v8
$ php --ri v8

For macOS php-v8 formulae and dependencies provided by phpv8/tap tap.

Building php-v8 from sources

git clone https://github.com/phpv8/php-v8.git
cd php-v8
phpize && ./configure && make
make test

To install extension globally run

$ sudo make install

Developers note

  • to be able to customize some tests make sure you have variables_order = "EGPCS" in your php.ini

  • export DEV_TESTS=1 allows to run tests that are made for development reasons (e.g. test some weird behavior or for debugging)

  • To prevent the test suite from asking you to send results to the PHP QA team do export NO_INTERACTION=1

  • To run tests with memory leaaks check, install valgrind and do export TEST_PHP_ARGS="-m"

  • To track memory usage you may want to use smem, pmem or even lsof to see what shared object are loaded and free to display free and used memory in the system.

  • pinepain/experimental may contain libv8 version that used in current master branch.

Docker

First, let's build docker image docker build -t phpv8/php-v8 . that we'll use later for development. By default, it contains PHP 7.2, though you can change that by passing --build-arg PHP=MAJOR.MINOR where MAJOR.MINOR version present in ondrej/php PPA.

To start playing with php-v8 in docker, run ```docker run -e TEST_PHP_ARGS -v pwd:/root/php-v8 -it phpv8/php-v8 bash``. Now you can build php-v8 as usual with `phpize && ./configure && make`. Don't forget to run `make test`!

Docs

We use Sphinx to buld docs and Read The Docs to host it.

To rebuild docs locally run in a project root:

virtualenv -p `which python` .virtualenv
source .virtualenv/bin/activate
cd docs
make html

Credits

My thanks to the following people and projects, without whom this extension wouldn't be what it is today. (Please let me know if I've mistakenly omitted anyone.)

  • v8js PHP extension which used as a reference on early stages;
  • Stefan Siegl, for his profound work on v8js PHP extension and for his personal time at helping building V8;
  • all v8js contributors;
  • Jérémy Lal, one of libv8 maintainers for his personal help on building V8 on Ubuntu;
  • John Gardner for dealing with V8 building system changes;
  • @ilovezfs for his help and mentoring on upgrading V8 homebrew formulae.

License

Copyright (c) 2015-2018 Bogdan Padalko <[email protected]>

php-v8 PHP extension is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].