script preaggregates.py
This commit is contained in:
@@ -1,16 +1,44 @@
|
||||
<?php
|
||||
// Runs the Python script, waits for completion, and returns its output.
|
||||
|
||||
$cmd = 'python3 /var/www/html/modules/EcmInvoiceOuts/ai/test.py';
|
||||
$output = [];
|
||||
$returnVar = 0;
|
||||
exec($cmd . ' 2>&1', $output, $returnVar);
|
||||
|
||||
if ($returnVar !== 0) {
|
||||
http_response_code(500);
|
||||
echo "Error running Python script:\n" . implode("\n", $output);
|
||||
exit;
|
||||
$bins = [
|
||||
'/var/www/venv/bin/python',
|
||||
'/usr/bin/python3.11',
|
||||
'/usr/bin/python3.10',
|
||||
'/usr/bin/python3.9',
|
||||
'/usr/local/bin/python3.11',
|
||||
'/usr/local/bin/python3.10',
|
||||
'/usr/local/bin/python3.9',
|
||||
'/usr/bin/python3',
|
||||
'python3',
|
||||
];
|
||||
foreach ($bins as $b) {
|
||||
$out = []; $ret = 0;
|
||||
exec("$b -V 2>&1", $out, $ret);
|
||||
echo htmlspecialchars("$b -> ".($out ? implode(' ', $out) : "not found / not executable")." (ret=$ret)")."<br>";
|
||||
}
|
||||
|
||||
// Expect a single line with the count
|
||||
echo trim(implode("\n", $output));
|
||||
//$python = '/usr/bin/python3';
|
||||
//$script = '/var/www/html/modules/EcmInvoiceOuts/ai/analysisAI.py';
|
||||
//$cmd = escapeshellcmd("$python $script");
|
||||
//
|
||||
//// odczyt
|
||||
//$output = [];
|
||||
//$returnVar = 0;
|
||||
//exec($cmd . ' 2>&1', $output, $returnVar);
|
||||
//$body = implode("\n", $output);
|
||||
//
|
||||
//// błąd Pythona
|
||||
//if ($returnVar !== 0) {
|
||||
// // pokaż błąd jako tekst
|
||||
// while (ob_get_level()) { ob_end_clean(); }
|
||||
// header_remove();
|
||||
// header('Content-Type: text/plain; charset=utf-8');
|
||||
// http_response_code(500);
|
||||
// echo "Error running Python script:\n".$body;
|
||||
// exit;
|
||||
//}
|
||||
//
|
||||
//// --- WYMUSZENIE RENDEROWANIA HTML ---
|
||||
//while (ob_get_level()) { ob_end_clean(); } // wyczyść wszystkie bufory
|
||||
//header_remove(); // usuń nagłówki ustawione wcześniej przez framework
|
||||
//header('Content-Type: text/html; charset=utf-8');
|
||||
//echo $body;
|
||||
//exit; // ZATRZYMAJ framework (np. SugarCRM), żeby nic już nie dopisywał
|
||||
|
||||
Reference in New Issue
Block a user