Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6349335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:35:44+00:00 2026-05-24T21:35:44+00:00

Trying to run old CGI-scripts under FastCGI. Printing without extra parameters gives proper output:

  • 0

Trying to run old CGI-scripts under FastCGI. Printing without extra parameters gives proper output: print $q->div( $q->param("text") )

But when printing out with extra parameters hash for CGI-methods print $q->div( {-id=>"id"}, $q->param("text") ), it ruins UTF-8 formed data (‘õäöüžš’ -> ‘õäöüžš’)

It happens only with CGI parameters, in script defined variables work fine (examples 3 and 4). Everything works perfecty under ordinary CGI (with “-utf8”-flag ).

FastCGI-turned example script, called as test.fcgi?text=õäöüžš should give four equal blocks:

#!/usr/bin/perl -w --

use strict;
use CGI::Fast qw(:all);
use locale;
use utf8;

BEGIN {
        binmode(STDIN);                       # Form data
        binmode(STDOUT, ':encoding(UTF-8)');  # HTML
        binmode(STDERR, ':encoding(UTF-8)');  # Error messages
}

my ($q) = ();
my $test = "õäöüžš";

while ($q = new CGI::Fast) {

        print $q->header(-type=>"text/html", -charset=>"utf-8"), 
                $q->start_html(-encoding=>"utf-8");

        print "1: ",
                $q->div(  $q->param('text') ),
                "<br />",
                "2: ",
                $q->div( {-id=>"id"},  $q->param('text') ),
                "<br />",
                "3: ",
                $q->div(  $test ),
                "<br />",
                "4: ",
                $q->div( {-id=>"id"},  $test ),
        $q->end_html();

}

First block is fine, second broken, 3rd and 4th also fine:

Ordinary CGI-example as that gives all 4 right way:

#!/usr/bin/perl -w --

use strict;
use CGI qw(:all -utf8);
use locale;
use utf8;

BEGIN {
        binmode(STDIN);                       # Form data
        binmode(STDOUT, ':encoding(UTF-8)');  # HTML
        binmode(STDERR, ':encoding(UTF-8)');  # Error messages
}

my ($q) = ();
my $test = "õäöüžš";
$q = new CGI;

        print $q->header(-type=>"text/html", -charset=>"utf-8"), 
                $q->start_html(-encoding=>"utf-8");

        print "1: ",
                $q->div(  $q->param('text') ),
                "<br />",
                "2: ",
                $q->div( {-id=>"id"},  $q->param('text') ),
                "<br />",
                "3: ",
                $q->div(  $test ),
                "<br />",
                "4: ",
                $q->div( {-id=>"id"},  $test ),
        $q->end_html();

It seems to me, that with FastCGI form-data has no utf8-flag on and i don’t understand, how to properly force it? Under CGI.pm i declare as:

use CGI qw(:all -utf8);

But how with FastCGI?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:35:45+00:00Added an answer on May 24, 2026 at 9:35 pm

    1) CGI::Fast is a subclass of CGI.pm, so you can specify the same import arguments.

    use CGI::Fast (-utf8);
    

    2) FCGI streams are implemented using the older stream API, TIEHANDLE. Applying PerlIO layers using binmode() has no effect. The proper solution would be to encode your data before outputting it, but if thats not an option I can offer this hotpatch:

    #!/usr/bin/perl
    use strict;
    use warnings;
    use utf8;
    
    use CGI::Fast (-utf8);
    use FCGI      ();
    use Encode    ();
    
    my $enc = Encode::find_encoding('UTF-8');
    my $org = \&FCGI::Stream::PRINT;
    no warnings 'redefine';
    local *FCGI::Stream::PRINT = sub {
        my @OUTPUT = @_;
        for (my $i = 1; $i < @_; $i++) {
            $OUTPUT[$i] = $enc->encode($_[$i], Encode::FB_CROAK|Encode::LEAVE_SRC);
        }
        @_ = @OUTPUT;
        goto $org;
    };
    
    my $literal = "õäöüžš";
    
    while (my $q = CGI::Fast->new) {
        print $q->header(-type => "text/html", -charset => "UTF-8"),
              $q->start_html(-encoding => "UTF-8"),
              $q->p("Text 1:" . $literal),
              $q->p("Text 2:" . $q->param('text')),
              $q->end_html;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation: I'm trying run an https store (xcart) under one domain secure.example.com and I
When trying to run an Eclipse Dynamic Web Project under a Tomcat setup using
I'm trying to run a process and do stuff with its input, output and
I am trying to build/run an old C++ system. I've already been able to
I´m trying to run an old .NET application from an ASP.NET website. After reading
I am trying to run an existing old mac os targeted application. When I
I'm trying to run the following PL/SQL on an Oracle 8i server (old, I
I am trying to move a old Classic ASP site to run in PHP.
Guys, I Started playing with django-nonrel, and am trying to run my old django
I am trying to run a old midi component in Delphi, and it works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.