0

Activeperl 5.16 + Windows 環境。

Windows マシン:

私の perl5 (リビジョン 5 バージョン 16 サブバージョン 3) 構成の概要:

Linux マシン:

私の perl5 (リビジョン 5 バージョン 14 サブバージョン 2) 構成の概要:

同じコードの Linux ベースではまったく発生しません。

これは、天気の gif 画像をフェッチし、いくつかの魔法を実行するコードです (インターネットが停止したり、リモート サーバーがフェッチの途中でレーダーの更新を行ったり、オフラインになったりした場合に備えて、フェールオーバー サポートのためにキャッシュされたディレクトリからサービスを提供します)。

sub get_map
{
    my $whichImage = $_[0];

    my $ua = LWP::UserAgent->new;
    my $cache_file      = $GLOB{'cache_mapA'};          # tempdata file path
    my $cache_file_age  = 100000;                       # this is used to determine if we have to get fresh data from the ems site will hold the tempdata file age in seconds 
    my $data            = '';                           # initializing empty data variable to enable later check for empty variable
    my $cache_time      = $GLOB{'cache_timeMap'};       # Max age of the temdata file in seconds
    my $useCached       = 0;
    my $url             = $GLOB{'mapAurl'};

    if( $whichImage eq "B" )
    {
        $cache_file     = $GLOB{'cache_mapB'};
        $url            = $GLOB{'mapBurl'};
    }

    if ( -s $cache_file )   # test existence of the tempdata file - if it has a size it exists
    {
        my $mtime           = ( stat $cache_file )[9];  # get the Unix time of the last change (in seconds)
        my $current_time    = time;                     # get the current Unix time (in  seconds)
        $cache_file_age     = $current_time - $mtime;       # get the age of the tempdata fileim seconds!       
    }

    if( $cache_file_age > $cache_time ) # check if we have to query the ems server 
    {
        my $response = $ua->get($url);

        if ($response->is_success) # checking if we were able to get the website
        {
            $data = $response->decoded_content( charset => 'none' );
            open my $filehandle , '>' , $cache_file or die 'Horribly';  
            binmode $filehandle;
            print $filehandle $data;
            close $filehandle;
        }
    }

    my $file = $cache_file;
    my $length = -s $file;

    print "Content-type: image/gif\n";
    print "Content-length: $length \n\n";

    binmode STDOUT;

    open (FH,'<', $file) || die "Could not open $file: $!";
    my $buffer = "";

    while (read(FH, $buffer, 10240)) 
    {
        print $buffer;
    }
    close(FH);
}

cache_mapA は tmp/map.A.gif とキャッシュを指します

http://mywebserver.com/whatever.cgi?type=mapAにアクセスすると、Google Chrome のデバッガーで net:: ERR_CONTENT_LENGTH_MISMATCHを示す破損した gif ファイルが生成されます。

http://mywebserver.com/tmp/map.A.gifにアクセスすると、ブラウザで問題なく動作します。

テスト ボックスでサーバー ソフトウェアを切り替えてみたところ、Apache と LightTPD の両方がこの動作を示しました。

これは非 Windows ベースのマシンで完全に正常に動作するため、アイデアがありません。

このセクションに問題がある可能性がありますが、私には問題ないようです。

print "Content-type: image/gif\n";
print "Content-length: $length \n\n";

binmode STDOUT;

open (FH,'<', $file) || die "Could not open $file: $!";
my $buffer = "";

while (read(FH, $buffer, 10240)) 
{
    print $buffer;
}
close(FH);

ヘルプ!

4

1 に答える 1