# Php server side events

**URL:** <https://www.ruby-forum.com/t/php-server-side-events/243157>\
**Category:** NGINX\
**Created:** [August 26, 2015, 9:34pm UTC](https://www.ruby-forum.com/t/php-server-side-events/243157 "2015-08-26T21:34:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [August 26, 2015, 9:34pm UTC](https://www.ruby-forum.com/t/php-server-side-events/243157/1 "2015-08-26T21:34:14Z")

</div>

I have several virtual servers operating with php-fpm perfectly fine.  
Buffering/caching with Wordpress is great. But now…

I’m trying to implement a new site that uses php for server-side events  
to stream live updates to clients. This is, I believe, properly done  
with an infinite loop in php that will send events as they occur. The  
problem is the events seem to be getting buffered and don’t appear.

If I write the php program to end after sending an event then it works.  
If I restart php-fpm then it works - at least for a while.

I’ve tried numerous config options - obviously what I’m trying isn’t  
working. Any suggestions?

–  
Daniel

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 26, 2015, 11:08pm UTC](https://www.ruby-forum.com/t/php-server-side-events/243157/2 "2015-08-26T23:08:53Z")

</div>

Hello!

On Wed, Aug 26, 2015 at 12:33:48PM -0700, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve tried numerous config options - obviously what I’m trying isn’t  
> working. Any suggestions?

By default, nginx only starts sending data to a client once it has  
a full buffer ready. If you want to stream data immediately,  
you have to switch off buffering - either with the fastcgi\_buffering  
directive, or using the X-Accel-Buffering header in a response.  
See [Module ngx\_http\_fastcgi\_module](http://nginx.org/r/fastcgi_buffering) for details.

Additionally, there are some buffering option in PHP. I’m not a  
PHP expert, but likely flush() function will help if the problem  
is on PHP side, see [PHP: flush - Manual](http://php.net/manual/en/function.flush.php).

–  
Maxim D.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 27, 2015, 1:54am UTC](https://www.ruby-forum.com/t/php-server-side-events/243157/3 "2015-08-27T01:54:12Z")

</div>

I thought I had done both…not seeing any difference in behaviour.

* * *

Daniel
