Solved

Set keep-alive connection

Posted on 2006-07-22
11
886 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
  • 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

809 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