[问题] php call python

楼主: lccf   2021-04-29 00:16:12
各位大大好
想请教一下
如果我目前想在linux appserv环境下 写一只PHP 去执行python
有参考相关的做法
PHP端
test.php
<?php
$command = escapeshellcmd('python3 /usr/custom/test.py');
$output = shell_exec($command);
echo $output;
?>
Python端: test.py
fp = open("filename.txt", "a")
# 写入 This is a testing! 到档案
fp.write("This is a testing!")
# 关闭档案
fp.close()
如果用以下执行时 http://127.0.0.1/test.php
会无法正常产生filename.txt
他会直接略过整只python, 不知是否有其他相关的作法 感谢
作者: penut85420 (PenutGGorz)   2021-04-29 00:50:00
考虑看看用python另外跑个server,用php发request给他
作者: oToToT (屁孩)   2021-04-29 01:31:00
权限问题?
作者: HamalAri (哈马‧阿里)   2021-04-29 09:37:00
我猜大概是 open_basedir 设定, 是说用 linux 还用 appserv 只是自找麻烦
作者: hms5232 (未)   2021-04-29 20:54:00
先用whereis python3看一下路径 打完整路径上去再试试看

Links booklink

Contact Us: admin [ a t ] ucptt.com