phpy automatically generates encapsulated modules for all PHP extension functions and classes using reflection tools. The package name is php and can be used directly.
from php import [ext-name]to import constants, functions, and classes defined in the PHP extension.
- Module names are all lowercase, for example,
PDO, corresponds to the modulephp.pdo. - Standard library functions are in the
php.stdmodule, for example,php.std.file_get_contents(). - Core language functions are in the
php.coremodule, for example,php.core.get_included_files(). - When the function prefix matches the extension name, the extension name prefix can be omitted, for example,
php.curl.curl_init()can be abbreviated asphp.curl.init(). - When a class name uses a namespace and matches the extension name, it will be converted to camel case, for example,
Swoole\Http\Serverbecomesphp.swoole.HttpServer. - When a function name uses a namespace, it will be converted to snake case, for example,
MongoDB\BSON\fromJSONbecomesphp.mongodb.bson_fromjson. - If a function or method name conflicts with a Python keyword, an underscore prefix will be automatically added, for example,
gmp_importbecomesphp.gmp._import.
from php import redis
db = redis.Redis()
db.connect("127.0.0.1", 6379, -1)
db.set("key", "swoole")
print(db.get("key"))from php import std
import phpy
errno = phpy.Reference()
errstr = phpy.Reference()
rs = std.stream_socket_client('tcp://127.0.0.1:9999', errno, errstr, 30)