Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 914 Bytes

tutorial.md

File metadata and controls

40 lines (30 loc) · 914 Bytes

Using PHP functionality in Python

Call PHP functions in Python code. The module name is phpy, which can be imported.

Example

from php import curl

ch = curl.init("https://www.baidu.com/")
curl.setopt(ch, curl.CURLOPT_RETURNTRANSFER, True)
rs = curl.exec(ch)
print(rs)

In the above code, we use the curl extension of PHP to request the homepage of Baidu.

Encapsulated modules

In addition to using the phpy module directly, you can also use encapsulated modules generated by reflection tools.

Generation

php tools/gen-pymod.php

Usage

from php import curl

ch = curl.init("https://www.baidu.com/")
curl.setopt(ch, curl.CURLOPT_RETURNTRANSFER, True)
rs = curl.exec(ch)
print(rs)