Как видно из заголовка, я запускаю скрипт Python из PHP с использованием shell_exec, и это работает, когда он запускается из сеанса SSH на мой веб-сервер с помощью команды php ./python.php. Я получаю ожидаемый результат.
Однако, когда страница загружается в веб-браузере, я просто получаю пустую веб-страницу без предупреждений PHP или ошибок. Любая помощь приветствуется.
python.php:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
ini_set('memory_limit', '-1');
$command = escapeshellcmd("python3 ./test.py 2>&1");
$output = shell_exec($command);
echo $output;
?>
test.py:
#!/usr/bin/env python
import pandas as pd
import math
import csv
url = 'https://afltables.com/afl/stats/2018a.html'
dfs = pd.read_html(url)
dfs = dfs[1]
dfs.to_csv('hmm.csv', sep=',', encoding='utf-8');
dfs = dfs[dfs.TM == "NM"]
dfs = dfs[dfs.GM > 3]
url = 'https://afltables.com/afl/seas/2018.html'
lad = pd.read_html(url)
scores = []
for index, row in dfs.iterrows():
score = (math.sqrt(row['CP']) * 2 + (row['IF']) * 2 + (row['CL']) ** 2)
scores.append([row['Player'], score])
pos = 1
scores = sorted(scores, key=lambda x: x[1], reverse=True)
for item in scores:
print(str(pos) + ". " + item[0] + ": " + str(item[1]))
pos = pos + 1