# Perl fastcgi buffering problem

**URL:** <https://www.ruby-forum.com/t/perl-fastcgi-buffering-problem/185130>\
**Category:** NGINX\
**Created:** [March 14, 2010, 6:51pm UTC](https://www.ruby-forum.com/t/perl-fastcgi-buffering-problem/185130 "2010-03-14T18:51:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamstef](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/6a8cbe/32.png) [@iamstef](https://www.ruby-forum.com/u/iamstef)\
**Post date:** [March 14, 2010, 6:51pm UTC](https://www.ruby-forum.com/t/perl-fastcgi-buffering-problem/185130/1 "2010-03-14T18:51:20Z")

</div>

Hi,

Im trying to see how certain Perl CGI scripts will  
work on nginx. Im using nginx stable on Solaris 10  
x86.

My configuration:

Perl CGI support: nginx-fcgi-0.4.3

> **[nginx.eu](http://www.nginx.eu/nginx-fcgi.html)**
>
> This domain may be for sale!

nginx.conf:

location ~ ^/cgi-bin/.\*.cgi$ {  
gzip off;  
fastcgi\_pass  
unix:/opt/sdr/report/ws/fastcgi\_temp/nginx-fcgi.sock;  
fastcgi\_read\_timeout 5m;  
fastcgi\_index index.cgi;  
fastcgi\_buffers 8 4k;  
fastcgi\_max\_temp\_file\_size 0;  
#  
# You may copy and paste the lines under or use include  
directive  
# include /etc/nginx/nginx-fcgi.conf;  
# In this example all is in one file  
#  
fastcgi\_param SCRIPT\_FILENAME  
/opt/sdr/report/docroot/$fastcgi\_script\_name;  
fastcgi\_param QUERY\_STRING $query\_string;  
fastcgi\_param REQUEST\_METHOD $request\_method;  
fastcgi\_param CONTENT\_TYPE $content\_type;  
fastcgi\_param CONTENT\_LENGTH $content\_length;  
fastcgi\_param GATEWAY\_INTERFACE CGI/1.1;  
fastcgi\_param SERVER\_SOFTWARE nginx;  
fastcgi\_param SCRIPT\_NAME $fastcgi\_script\_name;  
fastcgi\_param REQUEST\_URI $request\_uri;  
fastcgi\_param DOCUMENT\_URI $document\_uri;  
fastcgi\_param DOCUMENT\_ROOT $document\_root;  
fastcgi\_param SERVER\_PROTOCOL $server\_protocol;  
fastcgi\_param REMOTE\_ADDR $remote\_addr;  
fastcgi\_param REMOTE\_PORT $remote\_port;  
fastcgi\_param SERVER\_ADDR $server\_addr;  
fastcgi\_param SERVER\_PORT $server\_port;  
fastcgi\_param SERVER\_NAME $server\_name;  
}

and a simple script which should output the stdout to browser:

##############################################################  
use strict;

print “$ENV{SERVER\_PROTOCOL} 200 OK\n”;  
print “Server: $ENV{SERVER\_SOFTWARE}\n”;  
print “Content-type: text/plain\n\n”;

print “Starting for…\n”;  
$|=1;

for (my $i = 1; $i \<= 5; $i++) {  
print “Iteration: $i\n”;  
sleep 1;  
}

print “All done\n”;

This example uses non-parsed headers, like old days for Apache \< 1.x  
where  
the server buffered the output of std CGI scripts. Passing:

print “$ENV{SERVER\_PROTOCOL} 200 OK\n”;  
print “Server: $ENV{SERVER\_SOFTWARE}\n”;

should output directly to the browser the results, but it does not.  
Found out about: fastcgi\_max\_temp\_file\_size but that did not help.

Any ideas how can I see immediately the results from a simple CGI  
script in nginx/fcgi ?

thanks,  
Stefan

---

<div class="post-metadata">

**Author:** ![iamstef](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/6a8cbe/32.png) [@iamstef](https://www.ruby-forum.com/u/iamstef)\
**Post date:** [March 15, 2010, 1:03pm UTC](https://www.ruby-forum.com/t/perl-fastcgi-buffering-problem/185130/2 "2010-03-15T13:03:58Z")

</div>

On 19:50 Sun 14 Mar , Stefan P. wrote:

> 

Probable due the FastCGI specs in buffering the output.

stefan
