{"id":36253506,"url":"https://github.com/chenos/execjs","last_synced_at":"2026-01-11T07:03:25.214Z","repository":{"id":62501471,"uuid":"118459047","full_name":"chenos/execjs","owner":"chenos","description":"Run JavaScript code from PHP","archived":false,"fork":false,"pushed_at":"2018-03-30T13:43:24.000Z","size":45,"stargazers_count":31,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-29T23:46:34.801Z","etag":null,"topics":["execjs","javascript","php","php-v8","react","server-side-rendering","ssr","v8js","vue"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chenos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-22T13:13:07.000Z","updated_at":"2024-07-09T09:50:32.000Z","dependencies_parsed_at":"2022-11-02T12:15:20.273Z","dependency_job_id":null,"html_url":"https://github.com/chenos/execjs","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/chenos/execjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenos%2Fexecjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenos%2Fexecjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenos%2Fexecjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenos%2Fexecjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chenos","download_url":"https://codeload.github.com/chenos/execjs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenos%2Fexecjs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28296941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T04:44:51.577Z","status":"ssl_error","status_checked_at":"2026-01-11T04:44:44.232Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["execjs","javascript","php","php-v8","react","server-side-rendering","ssr","v8js","vue"],"created_at":"2026-01-11T07:03:24.529Z","updated_at":"2026-01-11T07:03:25.207Z","avatar_url":"https://github.com/chenos.png","language":"PHP","readme":"# ExecJs\n\n[![Build Status](https://travis-ci.org/chenos/execjs.svg?branch=master)](https://travis-ci.org/chenos/execjs) [![Coverage Status](https://coveralls.io/repos/github/chenos/execjs/badge.svg?branch=master\u0026v1)](https://coveralls.io/github/chenos/execjs?branch=master)\n\n## Requirements\n\n- PHP 7.0+\n- V8Js extension 2.0+\n\n## Installation\n\n```sh\ncomposer require chenos/execjs\n```\n\n## Testing\n\n```\nmake test\n```\n\n## Example\n\n```php\nmake example\n```\n\nAccess http://127.0.0.1:9999\n\n- [liquidjs](examples/liquidjs)\n- [marked \u0026 markdown-it](examples/markdown)\n- [react](examples/react-router)\n- [vue-simple](examples/vue-simple)\n- [vue-router](examples/vue-router)\n- [js-yaml](examples/yaml)\n\n## Usage\n\n```php\nuse Chenos\\ExecJs\\Context;\nuse Chenos\\V8JsModuleLoader\\ModuleLoader;\n\n$context = new Context('PHP');\n\n$context-\u003egetLoader()\n    -\u003esetEntryDir(__DIR__)\n    -\u003eaddVendorDir(__DIR__.'/node_modules')\n    -\u003eaddOverride('vue', 'vue/dist/vue.runtime.common.js')\n    ;\n// or\n$loader = new ModuleLoader();\n$loader-\u003esetEntryDir(__DIR__)\n    -\u003eaddVendorDir(__DIR__.'/node_modules')\n    -\u003eaddOverride('vue', 'vue/dist/vue.runtime.common.js')\n    ;\n$context-\u003esetLoader($loader);\n\n$context-\u003eeval(string $script);\n$context-\u003eload(string $module);\n$context-\u003erequire($module, string|array $identifier);\n$context-\u003eset(string $key, mixed $value, $global = false);\n```\n\n## API\n\n### eval\n\nEvaluates JavaScript code represented as a string.\n\n```php\npublic mixed function eval(string $script, int $flags = V8Js::FLAG_NONE, int $timeLimit = 0, int $memoryLimit = 0)\n```\n\nAlmost the same as `V8Js::executeString` except `$identifier` argument.\n\n```php\npublic mixed function V8Js::executeString(string $script, string $identifier = '', int $flags = V8Js::FLAG_NONE, int $timeLimit = 0, int $memoryLimit = 0)\n```\n\nUsage:\n\n```php\n$context-\u003eeval('1+1'); // 2\n```\n\n### load\n\nEvaluates JavaScript code represented from a file.\n\n```php\npublic mixed function load(string $module, int $flags = V8Js::FLAG_NONE, int $timeLimit = 0, int $memoryLimit = 0)\n```\n\n```php\n$context-\u003eload('./foo.js');\n// equals\n$str = $context-\u003egetLoader()-\u003eloadModule('./foo.js');\n$context-\u003eeval($str);\n```\n\n### require\n\nCommonJS module support to require external code.\n\n```php\npublic mixed function require(string $module, string|array $identifier = null)\n```\n\nUsage:\n\n```php\n$yaml = $context-\u003erequire('js-yaml');\n$yaml-\u003eload('a: b'); // ['a' =\u003e 'b']\n```\n\nString identifier\n\n```php\n$yaml = $context-\u003erequire('js-yaml', 'jsyaml');\n// equals\n$context-\u003eeval(\"var jsyaml = require('js-yaml'); jsyaml;\");\n\n// usage\n$yaml-\u003eload('a: b'); // ['a' =\u003e 'b']\n$context-\u003eeval(sprintf('jsyaml.dump(%s)', json_encode(['a' =\u003e 'b']))); // 'a: b'\n```\n\nArray identifier\n\n```php\n$context-\u003erequire('js-yaml', ['load', 'dump']);\n// equals\n$context-\u003eeval(\"var {load, dump} = require('js-yaml').load;\");\n\n$context-\u003eeval(\"load('a: b')\"); // ['a' =\u003e 'b']\n$context-\u003eeval(sprintf('dump(%s)', json_encode(['a' =\u003e 'b']))); // 'a: b'\n\n$context-\u003erequire('js-yaml', ['load' =\u003e 'yamlLoad']);\n// equals\n$context-\u003eeval(\"var yamlLoad = require('js-yaml').load;\");\n// es6: import {load as yamlLoad} from 'js-yaml'\n\n$context-\u003eeval(\"yamlLoad('a: b')\"); // ['a' =\u003e 'b']\n```\n\n### set\n\nAssign a property to make it accessible to the javascript context.\n\n```php\npublic Context function set(string $key, mixed $value, $global = false)\n```\n\nUsage:\n\n```php\n$context-\u003eset('foo', 'bar');\n$context-\u003eeval('PHP.foo'); // bar\n$context-\u003eeval('foo'); // error undefined\n\n$context-\u003eset('bar', 'baz', true);\n$context-\u003eeval('PHP.bar'); // baz\n$context-\u003eeval('bar'); // baz\n\n$context-\u003eset('process', [\n    'env' =\u003e [\n        'NODE_ENV' =\u003e 'production',\n    ],\n], true);\n\n$context-\u003eeval('process.env.NODE_ENV'); // production\n```\n\n## Global Variables\n\n- exit `V8Function`\n- PHP `V8Js`\n- print `V8Function`\n- require `V8Function`\n- sleep `V8Function`\n- var_dump `V8Function`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenos%2Fexecjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchenos%2Fexecjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenos%2Fexecjs/lists"}