I need to do some long process using Python which will be called using PHP(my main language) and display the result real time.
Lets say this is my Python script(a.py).
import time
for x in range(10):
print "S;adasdasd;",x
time.sleep(0.5)
I have try so many example from internet but always get same result. PHP always wait until script is done then displaying it.
Here is one of so many code i have tried.
header( 'Content-type: text/html; charset=utf-8' );
$handle = popen('python folder\\a.py', 'r');
while (!feof($handle)) {
echo fgets($handle);
flush();
ob_flush();
}
pclose($handle);
Did I miss something?
fread($handle, 1024);instead offgets?popenrather than usingfopen. Is it possible you could alter the code slightly to usefopenand set the URL to a website and just output the contents line by line. If that works then the issue would lie withinpopenrather than your server config, so may help to narrow down the issue.