php call python - Linux

Table of Contents



各位大大好

想請教一下

如果我目前想在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, 不知是否有其他相關的作法 感謝

--

All Comments

Jessica avatarJessica2021-04-29
考慮看看用python另外跑個server,用php發request給
Ula avatarUla2021-04-29
權限問題?
Tracy avatarTracy2021-04-30
我猜大概是 open_basedir 設定, 是說用 linux 還用 ap
pserv 只是自找麻煩
Ethan avatarEthan2021-04-30
先用whereis python3看一下路徑 打完整路徑上去再試試看
Sarah avatarSarah2021-05-01
乾 which啦打錯