温馨提示×

php怎么调用python接口

小亿
99
2023-12-09 03:11:31
栏目: 编程语言

要调用Python接口,可以使用PHP的exec()函数或shell_exec()函数来执行Python脚本。

下面是一种调用Python接口的示例代码:

<?php
$command = 'python /path/to/python_script.py arg1 arg2';
$result = exec($command);
// 或者使用 shell_exec() 函数
// $result = shell_exec($command);

echo $result;
?>

其中,/path/to/python_script.py 是你要调用的Python脚本的路径,arg1 arg2 是要传递给Python脚本的参数。执行完Python脚本后,会将结果保存在 $result 变量中,可以根据需要进行处理或输出。

请注意,在执行Python脚本时,需要确保PHP服务器上已经安装了Python,并且Python的路径正确。

0