Solved

Set keep-alive connection

Posted on 2006-07-22
11
885 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to delete rows in a file based on the file name. 5 53
perl split by | 2 90
crawling gofundme 4 120
collecting information 2 135
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now