1. 使用`shell_exec`函数:
```php
$pythonResult = shell_exec('python your_script.py');
echo $pythonResult;
2. 使用`exec`函数:
```php
exec('python your_script.py', $output);
$pythonResult = end($output);
echo $pythonResult;
3. 使用`passthru`函数:
```php
ob_start();
passthru('python your_script.py');
$pythonResult = ob_get_clean();
echo $pythonResult;
4. 使用`proc_open`函数:
```php
$descriptorspec = array(
0 => array("pipe", "r"), // 标准输入,子进程从此管道中读取数据
1 => array("pipe", "w"), // 标准输出,子进程向此管道中写入数据
2 => array("pipe", "w") // 标准错误,用于写入错误输出
);
$process = proc_open('python your_script.py', $descriptorspec, $pipes);
if (is_resource($process)) {
fclose($pipes); // 不需要向子进程传递任何输入,所以关闭此管道
$pythonResult = stream_get_contents($pipes);
fclose($pipes);
$errorResult = stream_get_contents($pipes);
fclose($pipes);
proc_close($process);
echo $pythonResult . "\n" . $errorResult;
}
请根据您的需求选择合适的方法。