Software Description
phpy is a library for interoperability between Python
PHP and Python . You can use the functions and class libraries of the Python language in Python, or use the packages of Python in Python. However, it is not a language embedder. The encoding still uses the native syntax of each language.PHP
PHP
Python
Python
PHP
phpy
It allows PHP
to call all Python
‘s packages, including the currently very popular PyTorch
, transformers
, TensorFlow
and other ‘ AI
libraries, as well as scientific computing libraries such as Numpy
, Pandas
, and can also use graphical interface libraries such as and .Scikit
PyQt
wxPython
- Currently only supports Linux platform (theoretically can support all operating systems, to be implemented)
- Does not support Python multithreading,
async-io
features
PHP calls Python
Compile and install, phpy.so
load as an extension, and modify php.ini
and append extension=phpy.so
.
example:
$os = PyCore::import("os");
$un = $os->uname();
echo strval($un);
Calling PHP from Python
Just C++ Mudule
import and load it.
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 principle
ZendVM
and are created at the same time in the process CPython VM
, and the functions are called each other directly in the process stack space C
. The only overhead is zval <-> PyObject
the conversion of the structure, so the performance is very high.
actual case
Implementation -based example tkinter
GUI
<?php
$tkinter = PyCore::import('tkinter');
$root = $tkinter->Tk();
$root->title('我的窗口');
$root->geometry("500x500");
$root->resizable(False, False);
$button = $tkinter->Button($root, text: "Click Me!!", command: PyCore::fn(function () {
var_dump(func_get_args());
echo 'click me!!' . PHP_EOL;
}));
$button->pack();
$tkinter->mainloop();