Python 官方文档:入门教程 => 点击学习
. 调用PHP 方法一: import subprocess #simple caller, disguard output subprocess.call("php /path/to/my/old/script.php")
import subprocess
#simple caller, disguard output
subprocess.call("php /path/to/my/old/script.php")
# if you want output
proc = subprocess.Popen("php /path/to/my/script.php", shell=True,
stdout=subprocess.PIPE)
script_response = proc.stdout.read()
方法二:
# shell execute PHP
def php(code):
# open process
p = Popen(['php'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, close_fds=True)
# read output
o = p.communicate(code)[0]
# kill process
try:
os.kill(p.pid, signal.SIGTERM)
except:
pass
# return
return o
To execute a particular file do this:
width = 100
height = 100
code = """<?php
include('/path/to/file.php');
echo start(""" + width + """, """ + height + """);
?>
"""
res = php(code)
--结束END--
本文标题: python调用PHP
本文链接: https://lsjlt.com/news/191642.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0