{"id":28425074,"url":"https://github.com/swoole/phpy","last_synced_at":"2025-06-28T08:32:11.221Z","repository":{"id":210680775,"uuid":"727141597","full_name":"swoole/phpy","owner":"swoole","description":"Connecting the Python and PHP ecosystems together","archived":false,"fork":false,"pushed_at":"2025-06-16T06:44:39.000Z","size":1957,"stargazers_count":602,"open_issues_count":4,"forks_count":50,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-06-16T07:25:12.193Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swoole.png","metadata":{"files":{"readme":"README-CN.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,"zenodo":null}},"created_at":"2023-12-04T09:15:17.000Z","updated_at":"2025-06-16T06:44:38.000Z","dependencies_parsed_at":"2024-04-09T09:41:44.144Z","dependency_job_id":"8886842d-228e-49b9-9162-8d2da846afd9","html_url":"https://github.com/swoole/phpy","commit_stats":null,"previous_names":["swoole/phpy"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/swoole/phpy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swoole%2Fphpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swoole%2Fphpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swoole%2Fphpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swoole%2Fphpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swoole","download_url":"https://codeload.github.com/swoole/phpy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swoole%2Fphpy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262400666,"owners_count":23305337,"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":[],"created_at":"2025-06-05T10:31:15.278Z","updated_at":"2025-06-28T08:32:11.216Z","avatar_url":"https://github.com/swoole.png","language":"PHP","funding_links":[],"categories":["How to use this list"],"sub_categories":["Recommended core stack"],"readme":"[English](README.md)\n\nphpy\n====\n`Python` 与 `PHP` 互调用库，可以在 `PHP` 中使用 `Python` 语言的函数和类库，或者在 `Python` 中使用 `PHP` 的包。\n但不是语言内嵌。编码依然使用各自的原生语法。\n\n![phpy ecosystems](docs/images/ecosystems.svg)\n\n- 查看 [中文文档](docs/cn/README.md)  \n- 支持 `Linux`/`Windows`/`macOS` 等多种操作和平台\n- 不支持 Python 多线程、`async-io` 特性\n- 需要 `PHP 8.1` 或更高版本\n\nPHP 调用 Python\n----\n编译安装 `phpy.so` 作为扩展加载，修改 `php.ini` 追加 `extension=phpy.so` 即可。\n\n例子：\n```php\n$os = PyCore::import(\"os\");\n$un = $os-\u003euname();\necho strval($un);\n```\n\nPython 中调用 PHP\n----\n直接作为 `C++ Mudule` ，import 加载即可。\n\n```python\nimport phpy\n\ncontent = phpy.call('file_get_contents', 'test.txt')\n\no = phpy.Object('redis')\nassert o.call('connect', '127.0.0.1', 6379)\nrdata = phpy.call('uniqid')\nassert o.call('set', 'key', rdata)\nassert o.call('get', 'key') == rdata\n```\n\n实现原理\n----\n在进程内同时创建了 `ZendVM` 和 `CPython VM`，直接在进程堆栈空间内使用 `C` 函数互相调用，\n开销只有 `zval \u003c-\u003e PyObject` 结构体转换，因此性能是非常高的。\n\n在基准测试中我们创建了一个 `PyDict` ，分别读写 `PHP` 代码和 `Python` 代码执行 `1000万次`。\n`phpy` 以 `PHP` 代码写入 `PyDict` 的性能比原生 `Python` 高 `14%`，读取性能高 `25%`。\n\n\u003e 详细细节请参考 [压力测试](docs/cn/benchmark.md)\n\n微信交流群\n----\n![Alt](https://www.swoole.com/static/image/shiwo-tech.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswoole%2Fphpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswoole%2Fphpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswoole%2Fphpy/lists"}