mardi 23 juin 2020

print Python output live with PHP

I would like to see the output of my Python Script live on a website.

I have a live output with this script php:

<?php

if (ob_get_level() == 0) ob_start();

for ($i = 0; $i<10; $i++){

        echo "<br>$i Line to show.";
        echo str_pad('',4096)."\n";

        ob_flush();
        flush();
        sleep(1);
}

echo "Done.";

ob_end_flush();

?>

It is the flush example script from the Php website and it works perfectly for me.

to run a python script i use this script:

<?php

exec("python3 app.py" ,$output);
print_r($output);

?>

how can I combine these two codes?

My python test script:

from time import sleep

print("Hallo 1")
sleep(2)
print("Hallo 2")
sleep(2)
print("Hallo 3")
sleep(2)

best regards




Aucun commentaire:

Enregistrer un commentaire