docs.roxen.comView this page in a printer friendly mode
DocsRoxenWebServer 5.4System Developer Manual PikeProgramming Languages
Copyright © 2018, Roxen Internet Software
Suggestions, comments & compliments


Pike Script
Pike Processing Instruction
Using In-Line Perl Code
Running Perl Scripts
Supported mod_perl API Methods
What is a CGI Script?
CGI Environment Variables
CGI I/O Via Standard Streams

Running Perl Scripts

With the "Script output" option of the Perl support module set to HTTP, it is possible to run old Perl CGI scripts more or less as they are, only with better performance, provided they do not rely on their environment being reset upon each run of the script. (This performance boost comes in part from the script already being loaded and compiled, thus staying resident in-between requests and in part from the fact that there is no need to fork off new processes for the script.)

The environment variables are the same as those available in standard CGI, plus those added by Roxen for your convenience.

As with CGI, anything you print to STDERR ends up in the server's general debug log file (or the console, in the event of your starting the server with the --once flag).

CGI-Style Scripts

A simple example of a traditional CGI script in Perl could look like:

#! /usr/local/bin/perl print "Content-type: text/plain\r\n\r\n"; print "Environment variables:\n"; for (sort keys %ENV) { print $_, "=", $ENV{$_}, "\n"; }

mod_perl-style Scripts

Turning this one into a mod_perl-style script, also runnable by the Perl support module and by some considered a bit tidier, might result in something along the lines of:

my $r = Roxen->request(); $r->print("Content-type: text/plain\r\n\r\n"); $r->print("Environment variables:\n"); for (sort keys %ENV) { $r->print($_, "=", $ENV{$_}, "\n"); }