{"id":13700113,"url":"https://github.com/phpv8/php-v8","last_synced_at":"2025-05-04T18:34:20.289Z","repository":{"id":146195367,"uuid":"63369562","full_name":"phpv8/php-v8","owner":"phpv8","description":"PHP extension for V8 JavaScript engine","archived":true,"fork":false,"pushed_at":"2018-07-15T14:19:33.000Z","size":2142,"stargazers_count":217,"open_issues_count":0,"forks_count":14,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-13T06:33:02.448Z","etag":null,"topics":["php","php-extension","php-javascript","php-js","php-v8","v8","v8-javascript-engine"],"latest_commit_sha":null,"homepage":"https://php-v8.readthedocs.io","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phpv8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-14T21:02:57.000Z","updated_at":"2024-09-21T22:15:51.000Z","dependencies_parsed_at":"2023-05-09T19:13:23.380Z","dependency_job_id":null,"html_url":"https://github.com/phpv8/php-v8","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpv8%2Fphp-v8","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpv8%2Fphp-v8/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpv8%2Fphp-v8/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpv8%2Fphp-v8/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpv8","download_url":"https://codeload.github.com/phpv8/php-v8/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252382954,"owners_count":21739245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","php-extension","php-javascript","php-js","php-v8","v8","v8-javascript-engine"],"created_at":"2024-08-02T20:00:48.730Z","updated_at":"2025-05-04T18:34:15.237Z","avatar_url":"https://github.com/phpv8.png","language":"PHP","readme":"# php-v8\nPHP extension for V8 JavaScript engine\n\n[![Build Status](https://api.travis-ci.org/phpv8/php-v8.svg?branch=master)](https://travis-ci.org/phpv8/php-v8)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/phpv8/php-v8/master/LICENSE)\n[![Docs](https://readthedocs.org/projects/php-v8/badge/)](https://php-v8.readthedocs.io)\n\n\n**This extension requires PHP \u003e= 7.2**. Last version that supports PHP 7.1 is v0.2.2 and for PHP 7.0 is v0.1.9.\n\n**This extension is still under heavy development and its public API may change without any warning. Use at your own risk.**\n\nWork in progress documentation could be found at https://php-v8.readthedocs.io. You can also use tests and \nstubs as reference.\n\n## Why (aka Rationale)\n\nThis tool solves following domain problems:\n\n - execute arbitrary untrusted code from user;\n - provide restricted/experimental api to end-user;\n - allow to use that with scripting/DSL language;\n - limit execution time and used memory;\n - use common language that is familiar to large audience;\n - be well-maintainable and mature.\n\nBy accident (not by design) this tool could also be used to:\n\n - render React/Vue/Angular components in PHP;\n - implement node.js in PHP;\n - increase the number of \"why\", \"why not just \u003c...\u003e\" questions.\n\nIf you have any other use, feels free to share\n\n\n## About\n[php-v8](https://github.com/phpv8/php-v8) is a PHP 7.x extension\nthat brings [V8](https://developers.google.com/v8/intro) JavaScript engine API to PHP with some abstraction in mind and\nprovides an accurate native V8 C++ API implementation available from PHP.\n\n**Key features:**\n - provides up-to-date JavaScript engine with recent [ECMA](http://kangax.github.io/compat-table) features supported;\n - accurate native V8 C++ API implementation available from PHP;\n - solid experience between native V8 C++ API and V8 API in PHP;\n - no magic; no assumptions;\n - does what it is asked to do;\n - hides complexity with isolates and contexts scope management under the hood;\n - provides a both-way interaction with PHP and V8 objects, arrays and functions;\n - execution time and memory limits;\n - multiple isolates and contexts at the same time;\n - it works.\n\nWith this extension almost everything that the native V8 C++ API provides can be used. It provides a way to pass PHP scalars,\nobjects and functions to the V8 runtime and specify interactions with passed values (objects and functions only, as scalars\nbecome js scalars too). While specific functionality will be done in PHP userland rather than in this C/C++ extension,\nit lets you get into V8 hacking faster, reduces time costs and gives you a more maintainable solution. And it doesn't\nmake any assumptions for you, so you stay in control, it does exactly what you ask it to do.\n\nWith php-v8 you can even implement nodejs in PHP. Not sure whether anyone should/will do this anyway, but it's doable.\n\n## Demo\n\nHere is a [Hello World][v8-hello-world]\nfrom V8 [Getting Started][v8-intro] developers guide page implemented in PHP with php-v8:\n\n```php\n\u003c?php\n$isolate = new \\V8\\Isolate();\n$context = new \\V8\\Context($isolate);\n$source = new \\V8\\StringValue($isolate, \"'Hello' + ', World!'\");\n\n$script = new \\V8\\Script($context, $source);\n$result = $script-\u003erun($context);\n\necho $result-\u003evalue(), PHP_EOL;\n```\n\nwhich will output `Hello, World!`. See how it's shorter and more readable than [that C++ version][v8-hello-world]?\nAnd it also doesn't limit you from V8 API utilizing to implement more amazing stuff.\n\n## Quick start\n\nYou can try php-v8 in `phpv8/php-v8`: `docker run -it phpv8/php-v8 bash -c \"php test.php\"`\n\n## Stub files\n\nIf you are also using Composer, it is recommended to add the [php-v8-stub][php-v8-stubs]\npackage as a dev-mode requirement. It provides skeleton definitions and annotations to enable support for auto-completion\nin your IDE and other code-analysis tools.\n\n    composer require --dev phpv8/php-v8-stubs\n\n## High-level wrapper library\n\nThere is [phpv8/js-sandbox](https://github.com/phpv8/js-sandbox) library that provides high-level abstraction\non top of php-v8 extension and makes embedding JavaScript in PHP easier.\n\n## Installation\n\n### Requirements\n\n#### V8\nYou will need a recent v8 Google JavaScript engine version installed. At this time v8 \u003e= 6.6.313 required.\n\n#### PHP\n**This extension requires PHP \u003e= 7.2**. Last version that supports PHP 7.1 is v0.2.2 and for PHP 7.0 is v0.1.9.\n\n#### OS\nThis extension works and tested on x64 Linux and macOS. As of written it is Ubuntu 16.04 LTS Xenial Xerus, amd64\nand macOS 10.12.5. Windows is not supported at this time.\n\n### Quick guide\n\n#### Ubuntu\n\n```\n$ sudo add-apt-repository -y ppa:ondrej/php\n$ sudo add-apt-repository -y ppa:pinepain/php\n$ sudo apt-get update -y\n$ sudo apt-get install -y php7.2 php-v8\n$ php --ri v8\n```\n\nWhile [pinepain/php](https://launchpad.net/~pinepain/+archive/ubuntu/php) PPA targets to contain all necessary\nextensions with dependencies, you may find\n[pinepain/libv8](https://launchpad.net/~pinepain/+archive/ubuntu/libv8) and \n[pinepain/php](https://launchpad.net/~pinepain/+archive/ubuntu/php-v8) standalone PPAs useful.\n\n\n#### OS X (homebrew)\n\n```\n$ brew tap homebrew/dupes\n$ brew tap homebrew/php\n$ brew tap phpv8/tap\n$ brew install php72 php72-v8\n$ php --ri v8\n```\n\nFor macOS php-v8 formulae and dependencies provided by [phpv8/tap](https://github.com/phpv8/homebrew-tap) tap.\n\n### Building php-v8 from sources\n\n```\ngit clone https://github.com/phpv8/php-v8.git\ncd php-v8\nphpize \u0026\u0026 ./configure \u0026\u0026 make\nmake test\n```\n\nTo install extension globally run\n\n```\n$ sudo make install\n```\n\n## Developers note\n\n - to be able to customize some tests make sure you have `variables_order = \"EGPCS\"` in your php.ini\n - `export DEV_TESTS=1` allows to run tests that are made for development reasons (e.g. test some weird behavior or for debugging)\n - To prevent the test suite from asking you to send results to the PHP QA team do `export NO_INTERACTION=1`\n - To run tests with memory leaaks check, install `valgrind` and do `export TEST_PHP_ARGS=\"-m\"`\n\n - To track memory usage you may want to use `smem`, `pmem` or even `lsof` to see what shared object are loaded\n   and `free` to display free and used memory in the system.\n - [pinepain/experimental](https://launchpad.net/~pinepain/+archive/ubuntu/experimental) may contain `libv8` \n   version that used in current `master` branch.\n\n### Docker\n\nFirst, let's build docker image `docker build -t phpv8/php-v8 .` that we'll use later for development. By default, \nit contains PHP 7.2, though you can change that by passing `--build-arg PHP=MAJOR.MINOR` where MAJOR.MINOR version\npresent in [ondrej/php](https://launchpad.net/~ondrej/+archive/ubuntu/php) PPA.\n\nTo start playing with php-v8 in docker, run ```docker run -e TEST_PHP_ARGS -v `pwd`:/root/php-v8 -it phpv8/php-v8 bash``.\nNow you can build php-v8 as usual with `phpize \u0026\u0026 ./configure \u0026\u0026 make`. Don't forget to run `make test`!\n\n### Docs\n\nWe use [Sphinx](http://www.sphinx-doc.org/en/master/) to buld docs and [Read The Docs](https://readthedocs.org/) to host\nit.\n\nTo rebuild docs locally run in a project root:\n\n    virtualenv -p `which python` .virtualenv\n    source .virtualenv/bin/activate\n    cd docs\n    make html\n\n\n## Credits\n\nMy thanks to the following people and projects, without whom this extension wouldn't be what it is today.\n(Please let me know if I've mistakenly omitted anyone.)\n\n - [v8js](https://github.com/phpv8/v8js) PHP extension which used as a reference on early stages;\n - [Stefan Siegl](https://github.com/stesie), for his profound work on [v8js](https://github.com/phpv8/v8js)\n   PHP extension and for his personal time at helping building V8;\n - all [v8js](https://github.com/phpv8/v8js) [contributors](https://github.com/phpv8/v8js/graphs/contributors);\n - Jérémy Lal, one of [libv8](https://anonscm.debian.org/git/collab-maint/libv8.git) maintainers for his personal\n   help on building V8 on Ubuntu;\n - [John Gardner](https://github.com/Alhadis) for dealing with V8 building system changes;\n - [@ilovezfs](https://github.com/ilovezfs) for his help and mentoring on upgrading V8 homebrew formulae.\n\n## License\n\nCopyright (c) 2015-2018 Bogdan Padalko \u0026lt;thepinepain@gmail.com\u0026gt;\n\n[php-v8](https://github.com/phpv8/php-v8) PHP extension is licensed under the [MIT license](http://opensource.org/licenses/MIT).\n\n\n[v8-hello-world]: https://chromium.googlesource.com/v8/v8/+/master/samples/hello-world.cc\n[v8-intro]: https://developers.google.com/v8/intro\n[php-v8-stubs]: https://github.com/phpv8/php-v8-stubs\n","funding_links":[],"categories":["跨语言"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpv8%2Fphp-v8","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpv8%2Fphp-v8","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpv8%2Fphp-v8/lists"}