psx/v8
Composer 安装命令:
composer require psx/v8
包简介
Helper library for the php-v8 extension
关键字:
README 文档
README
About
This is a small helper library which simplifies working with the PHP V8 extension (https://github.com/pinepain/php-v8). It adds small wrapper classes which help with the type juggling between PHP and the V8 environment.
Usage
<?php $script = <<<JS var message = 'Hello ' + console.foo; resp = { message: console.log(message), bar: function(data){ return 'Foo ' + data; }, foo: 'bar' }; JS; $environment = new \PSX\V8\Environment(); $environment->set('console', [ 'foo' => 'foo', 'log' => function($value){ return $value . ' and bar'; } ]); $environment->run($script); $resp = $environment->get('resp'); echo $resp->get('message') . "\n"; // Hello foo and bar echo $resp->get('bar')(['test']) . "\n"; // Foo test echo $resp->get('foo') . "\n"; // bar
Objects
It is also possible to expose complete PHP classes to the V8 engine. Therefor
the class has to implement the PSX\V8\ObjectInterface interface. There is also
a PSX\V8\ReflectionObject object which automatically exposes all public
properties and methods. The javascript defined above would also work with the
following environment:
<?php class Console { public $foo; public function __construct() { $this->foo = 'foo'; } public function log($value) { return $value . ' and bar'; } } $console = new Console(); $environment = new \PSX\V8\Environment(); $environment->set('console', new \PSX\V8\Object\ReflectionObject($console)); $environment->run($script); $resp = $environment->get('resp');
psx/v8 适用场景与选型建议
psx/v8 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.97k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「v8」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 psx/v8 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 psx/v8 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 10.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2016-09-20