Solved

Set keep-alive connection

Posted on 2006-07-22
11
902 Views
Last Modified: 2012-06-27
How can Set keep-alive connection in perl script.
Currently this script reply with following headers:

HTTP/1.1 200 OK
Date: Sat, 22 Jul 2006 20:32:26 GMT
Server: Apache
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

If I try to return header like
print "Content-Type: text/html\nConnection: Keep-Alive\nKeep-Alive: timeout=300, max=5\n\n";


it change headers to
HTTP/1.1 200 OK
Date: Sat, 22 Jul 2006 20:32:26 GMT
Server: Apache
Connection: Keep-Alive, close
Keep-Alive: timeout=300, max=5
Transfer-Encoding: chunked
Content-Type: text/html
0
Comment
Question by:serg111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17163742
print "keep-alive:42\n";
0
 
LVL 2

Author Comment

by:serg111
ID: 17164371
It does not help - still "Connection: close"
it change reply headers to

HTTP/1.1 200 OK
Date: Sun, 23 Jul 2006 22:03:08 GMT
Server: Apache
keep-alive: 42
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17164410
print "Connection:keep-alive\r\nkeep-alive:42\r\n";

> Connection: Keep-Alive, close
if you realy print the headers as you posted in your question, then the server added your headers to its own ones, in that case you need to configure your server for NPH - none-parsing  headers (means that the headers of the CGI are used)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:serg111
ID: 17164602
Yes, it looks like server added own headers.
I dont have access to server configuration.
Can enable NPH inside script?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17164950
use CGI;
my $q = new CGI;

print $query->header(-type=>'text/htmlf',
                       -nph=>1,
                       -status=>'402 Payment required',
                       -Keep-Alive=>'42');
                  
0
 
LVL 2

Author Comment

by:serg111
ID: 17165136
It generates 500 Internal Server Error
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17165161
I had a slight typo.  Change to

use CGI::Carp qw(fatalsToBrowser);
use CGI;
my $q = new CGI;

print $query->header(-type=>'text/html',
                    -nph=>1,
                    -status=>'402 Payment required',
                    -Keep-Alive=>'42');
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17165165
Sorry, still a typo above, $query should be $q, ie:

I had a slight typo.  Change to

use CGI::Carp qw(fatalsToBrowser);
use CGI;
my $q = new CGI;

print $q->header(-type=>'text/html',
               -nph=>1,
               -status=>'402 Payment required',
               -Keep-Alive=>'42');
0
 
LVL 17

Accepted Solution

by:
mjcoyne earned 125 total points
ID: 17165180
There are two other ways to put CGI.pm into NPH mode.

1. With the use statement:
      use CGI qw(:standard -nph)
     

2. By calling the nph() method with a non-zero parameter at any point after using CGI.pm in your program:
      CGI->nph(1)

Also, according to Lincoln Stein (CGI.pm's autour; see http://stein.cshl.org/WWW/CGI/#nph) "IIS and many Unix servers look at the beginning of the script's name for the prefix "nph-"."  Try changing your script name from 'myscript.pl' to 'nph-myscript.pl'?

What server are you using?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17165246
Also note that modern versions of CGI.pm try to automatically detect when to use NPH mode, but obviously it's not foolproof.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17165638
keep in mind, that NPH is a configuration of the web server, hence the suggested methods must not work if the web server is configured to add its own headers and (mainly) discard thos from its applications
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question