Hey guys,

I thought CGI::Session could work fine with CGI::Fast for creating & manipulating Sessions.

For this is the first time I use FastCGI, I wrote a test script first:
#!/usr/bin/perl #/var/www/htdocs/index.fcgi use CGI::Fast qw(:standard); use CGI; use CGI::Session; while ($q = new CGI::Fast) { my $session = CGI::Session->new ("driver:file", $q, {Directory => +'/tmp'}) or die "Session Initializing Failed.\n$!"; $session->expire('60'); $session->param('s1', 'XXX-S1-XXX'); $session->param('s2', 'XXX-S2-XXX'); $session->param('s3', 'XXX-S3-XXX'); print $session->header ( -type => 'text/html', -charset => 'utf-8', -title => 'test page'); my $var = $q->param('var'); print "var = $var."; print end_html; }
This looks fine when I run this script with `perl /var/www/htdocs/index.fcgi` under command line, it created a session file under "/tmp".

But when I access this page via web browser, it won't create a session file(at least there's no new session file in /tmp), but the page output was fine(include the value of $var).

Do you have any idea with this?


Thank you Almut, for helping me again, you are so cool. And thanks to everyone here. This problem has solved by add a statement "$session->flush();" to the last line of loop.
As cpan said:

flush()
Synchronizes data in memory with the copy serialized by the driver. Call flush() if you need to access the session from outside the current session object. You should call flush() sometime before your program exits.
As a last resort, CGI::Session will automatically call flush for you just before the program terminates or session object goes out of scope. Automatic flushing has proven to be unreliable, and in some cases is now required in places that worked with CGI::Session 3.x.
Always explicitly calling flush() on the session before the program exits is recommended. For extra safety, call it immediately after every important session update.

I was confused, I thought flush() was just like delete(), because that word made me to think of "flushing a toilet".
haha

In reply to SOLVED: How to create sessions via FastCGI? by Ray.Zachary

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.