Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Set keep-alive connection

Posted on 2006-07-22
11
Medium Priority
?
930 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
Industry Leaders: 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 500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Six Sigma Control Plans

688 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