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

**URL:** <https://forum.ansible.com/t/how-to-get-real-time-output-from-ansible-playbook-process-when-called-in-php/20289>\
**Category:** Ansible Project\
**Created:** [January 20, 2016, 1:08pm UTC](https://forum.ansible.com/t/how-to-get-real-time-output-from-ansible-playbook-process-when-called-in-php/20289 "2016-01-20T13:08:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sally\_Paner](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@Sally\_Paner](https://forum.ansible.com/u/Sally_Paner)\
**Post date:** [January 20, 2016, 1:08pm UTC](https://forum.ansible.com/t/how-to-get-real-time-output-from-ansible-playbook-process-when-called-in-php/20289/1 "2016-01-20T13:08:53Z")

</div>

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](http://selenium1.example.com)]

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

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[selenium1.example.com](http://selenium1.example.com) : ok=2 changed=0 unreachable=0 failed=0

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 20, 2016, 2:04pm UTC](https://forum.ansible.com/t/how-to-get-real-time-output-from-ansible-playbook-process-when-called-in-php/20289/2 "2016-01-20T14:04:27Z")

</div>

There is no currently available 'intermediate updates' feature.

---

<div class="post-metadata">

**Author:** ![Sally\_Paner](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@Sally\_Paner](https://forum.ansible.com/u/Sally_Paner)\
**Post date:** [January 21, 2016, 11:36am UTC](https://forum.ansible.com/t/how-to-get-real-time-output-from-ansible-playbook-process-when-called-in-php/20289/3 "2016-01-21T11:36:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 21, 2016, 1:51pm UTC](https://forum.ansible.com/t/how-to-get-real-time-output-from-ansible-playbook-process-when-called-in-php/20289/4 "2016-01-21T13:51:02Z")

</div>

you are probably buffering the output in php

---

<div class="post-metadata">

**Author:** ![Sally\_Paner](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@Sally\_Paner](https://forum.ansible.com/u/Sally_Paner)\
**Post date:** [January 27, 2016, 10:57am UTC](https://forum.ansible.com/t/how-to-get-real-time-output-from-ansible-playbook-process-when-called-in-php/20289/5 "2016-01-27T10:57:01Z")

</div>

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.
