How to disable output buffering with PHP and nginx

B.R. reallfqq-nginx at
Tue Oct 8 02:57:14 UTC 2013

I took a bit of time to do that... TBH I lost a lot of time finding a way
to record  traffic to a locally hosted Web server in Windows... :o\
Why would people host stuff with Windows? oO

Anyway. Here are the details:

nginx 1.5.6
PHP 5.4.20 Thread-Safe
Wireshark 1.10.2
I took the liberty of upgrading test components to the latest release in
the same branch, since some bugs of interest might have been corrected.

I didn't go far on the PHP side, but I noticed on early captures that PHP
was still sending everything after 5 seconds.

I cheated a little bit by modifying the test file to use the PHP flush()
procedure which forces buffers to be emptied and content sent to the client.

I then noticed on the capture that PHP was rightfully sending the content
in 2 parts as expected but somehow nginx was still waiting for the last
parto to arrive before sending content to the client.

There is still work to be done on the nginx side. Since we are on the nginx
mailing list, you may prioritize and see to the PHP part later on. :o)

Every modification I made to the original nginx.conf file is self-contained
in the location serving '.php' files.
How to reproduce:
The main concern here was to record traffic between nginx and PHP. Here are
the steps for a successful operation.

   1. Use the nginx configuration provided as attachment (nginx.conf to put
   in <nginx dir>\conf\, overwriting the default one)
   2. Place the test script in <nginx dir>\html\
   3. Use the PHP configuration provided as attachement (php.ini to put in
   <PHP dir>)
   4. Modify Windows' routing table to force local traffic to make a round
   trip to the nearest router/switch (local traffic can't be recorded on
   modern Windows) :
   5. In cmd.exe, type 'route add <computer external IP address> <gateway
   IP address>' (you'll find required information with a quick 'ipconfig')
   6. Start PHP with following arguments (either command-line or through a
   shortcut): 'php-cgi.exe -b <computer external IP address>:9000'
   7. Start nginx (simply double click on it)
   8. Check that 2 nginx processes and 1 php-cgi.exe process exist in the
   task manager.
   9. Check (through 'netstat -abn') that php-cgi.exe is listening on
   <computer external IP address>:9000
   10. Start Wireshark recording on the interface related to the IP address
   used before (or all interfaces) with capture filter 'port 9000'
   11. Browse to http://localhost/test.php
   12. Stop Wireshark recording

You'll find my recording of the backend traffic as attachement.
Please ignore the duplicated traffic (ad traffic going forth and back on
the network interface is recorded 2 times total: that's a drawback to the
'hack' setup you need on Windows to record local traffic...).

Hope that'll help
*B. R.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginx.conf
Type: application/octet-stream
Size: 2806 bytes
Desc: not available
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.php
Type: application/x-httpd-php
Size: 77 bytes
Desc: not available
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: php.ini
Type: application/octet-stream
Size: 68879 bytes
Desc: not available
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginx_php_backend.pcapng
Type: application/octet-stream
Size: 5592 bytes
Desc: not available
URL: <>

More information about the nginx mailing list