How to get real time output from ansible-playbook process when called in PHP?

I have a simple PHP script that runs ansible-playbook and polls the output. It seems that ansible runs to completion before it displays the output.
This is my simple code:
(process.php)

`

$handle = popen(“ansible-playbook set-mysqld-max-connection-with-template.yml”, “r”);

while(!feof($handle)) {
$buffer = fgets($handle);
echo $buffer . “\n”;
usleep(100000); //sleep for 0.1 seconds
}
pclose($handle);

`

Output:

`

PLAY [web] ********************************************************************

GATHERING FACTS ***************************************************************
ok: [selenium1.example.com]

TASK: [set-mysqld-max-connection-with-template | set mysqld (my.cnf) max_connection with template] ***
ok: [selenium1.example.com]

PLAY RECAP ********************************************************************
selenium1.example.com : ok=2 changed=0 unreachable=0 failed=0

`

There is no currently available 'intermediate updates' feature.

Hi Brian;

Thanks for the reply. I am just wondering that if I run ansible-playbook directly on the command line, it gives me real-time output, but if called from PHP it seems that ansible-playbook waits to finish the playbook before it returns any output.

you are probably buffering the output in php

Hi Brian;

I’ve resolved my problem by installing ansible through git because it pulls the latest version of ansible. My previous ansible was installed through yum. Thanks.