swoole/phpy
Composer 安装命令:
composer require swoole/phpy
包简介
Connecting the Python and PHP ecosystems together
README 文档
README
phpy
A library for inter-calling Python and PHP.
You can use Python functions and libraries in PHP, or use PHP packages in Python.
- See documents: docs/en/README.md
- Supports
Linux/Windows/macOS - Not support Python
threadingorasync-iofeatures - Require
PHP 8.1or later version
py2php
py2php is online utility that will auto-translate python code into PHP code.
Calling Python from PHP
Compile and install phpy.so as an extension, and append extension=phpy.so to php.ini.
PHP Example:
$os = PyCore::import("os"); echo $os->uname();
Transformers
$transformers = PyCore::import('transformers'); $AutoTokenizer = $transformers->AutoTokenizer; $AutoModelForSequenceClassification = $transformers->AutoModelForSequenceClassification; $os = PyCore::import('os'); $os->environ['https_proxy'] = getenv('https_proxy'); $tokenizer = $AutoTokenizer->from_pretrained("lxyuan/distilbert-base-multilingual-cased-sentiments-student"); $model = $AutoModelForSequenceClassification->from_pretrained("lxyuan/distilbert-base-multilingual-cased-sentiments-student");
Calling PHP from Python
Simply import it as a C++ Mudule.
Python Example:
import phpy content = phpy.call('file_get_contents', 'test.txt') o = phpy.Object('redis') assert o.call('connect', '127.0.0.1', 6379) rdata = phpy.call('uniqid') assert o.call('set', 'key', rdata) assert o.call('get', 'key') == rdata
Implementation
It creates ZendVM and CPython VM in the process at the same time, and directly uses C functions to call each other in the process stack space.
The overhead is only the conversion of zval <-> PyObject structures, so the performance is very high.
In the benchmark test, we created a PyDict and executed PHP code and Python code to read and write 10 million times respectively.
The performance of phpy writing PyDict with PHP code is 14% higher than the native Python, and the read performance is 25% higher.
More details: docs/en/benchmark.md
swoole/phpy 适用场景与选型建议
swoole/phpy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.06k 次下载、GitHub Stars 达 649, 最近一次更新时间为 2023 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「python」 「ai」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 swoole/phpy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 swoole/phpy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 swoole/phpy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Non-standard PHP library (NSPL) - functional primitives toolbox and more
PHP implementation of python's struct module.
Alfabank REST API integration
Install igc2kmz in your PHP project with ease
PHP client for Celery task queue base swoole ext by memory-resident, and edit by gjedeer/celery-php
Extracted Emoji One CSS and converters in PHP / Python / JS / Meteor / Awesome font.
统计信息
- 总下载量: 8.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 650
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2023-12-11