I had a really strange error on my cgi app.
I also found a solution.. and it makes about as much sense to me as my ex girlfriend..

It deals with Time::Format 1.09
A certain time format string actually crashes my cgi with no mercy- with silence to STDERR or STDOUT (yes, i'm tailing the logfile, etc etc etc ..) - but called via regular cli, it causes no problems.

In my CGI app, I had a crash recently that I tracked down to this:

my $last_login = 1231357784; my $ll = Time::Format::time_format( 'Weekday Month dth yyyy, h:mm', $l +ast_login ); print STDERR "We should get here\n"; # but we dont
However this works swell:
my $last_login = 1231357784; my $ll = Time::Format::time_format( 'mm/dd/yy hh:mm', $last_login ); print STDERR "We should get here\n"; # and we do

I thought maybe I had a messed up time format string.. But I had been using this Time::Format string for a while.. so.. Just for curiosity.. I wrote this cgi, a simple script with no crazy deps, none of my other code etc.. just a real sanity check here..

#!/usr/bin/perl -w use strict; use CGI; use Time::Format; my $last_login = 1231357784; my $c = new CGI; print $c->header; #my $a = Time::Format::time_format( 'mm/dd/yy hh:mm', $last_login ); # + time format string i see working fine my $a = Time::Format::time_format( 'Weekday Month dth yyyy, h:mm', $la +st_login ); # time format string that crashes print "last login $a";

Which, guess what... crashes.
However - If I run from the command line...

root@thalidomide# perl /var/www/cgi-bin/script.cgi
Content-Type: text/html; charset=ISO-8859-1

last login Wednesday January 7th 2009, 14:49

So I changed it around to use the other string 'mm/dd/yy hh:mm' and it works again via cgi.. ... WTF??

As well as via obviously, cli.. works fine and outputs

root@thalidomide# perl /var/www/cgi-bin/script.cgi
Content-Type: text/html; charset=ISO-8859-1

last login 01/07/09 14:49
update

(I should have noted that this error did not happen on all servers, some worked fine. This is in regards to a failing server.. )

From man Time::Format: Time::Format_XS is optional but will make C<%time> and C<time_format> much faster. The version of Time::Format_XS installed must match the version of Time::Format installed; otherwise Time::Format will not use it (and will issue a warning).

I didn't get a warning. I got the silent treatment. (Much like my ex girlfriend when she left me.. (it'll take a coder to find a pattern here))

So.. on the server that crashes (via cgi, no servers crash on cli).
Time::Format_XS 1.02
Time::Format 1.09

Thus.. cpan Time::Format_XS .. we *have* the most current version.

Thus.. I look on the working server.. what is the version of Time::Format and Time::Format_XS there? Same Time::Format.. Missing Time::Format_XS.

Go back to the server crashing via cgi.. locate Format_XS.pm .. rm it, voila. Works fine, without using BEGIN { $Time::Format::NOXS=1; }.

Still unresolved .. why did it always work via cli? Why only on one time format string but not another??? Very interesting.

Thanks to Charles Hamilton for solving that. Perlbotics, for figuring out a solution in the first place and where to look!


In reply to Time::Format string that works in cli crashes cgi by leocharre

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.