Hello Wise Monks,

I'm having problems with HTTP::Daemon when serving multiple images. I found this post http://use.perl.org/~jjohn/journal/9030 describing the problem I was getting and added $SIG{'PIPE'} = 'IGNORE'; to the top of the script. That helped, but it still randomly doesn't display one or more of the images.

Ok, here is the long version of how I came to this problem. I originally couldn't get it to serve more than one image. If there were 2 images on the page the webserver wouldn't show any of them after the first image. It would serve the page and the first image and then sit there.

So I searched the web and found this post http://use.perl.org/~jjohn/journal/9030 describing exactly the problem I was having. It stated that it was a IO::Socket::INET issue. I followed his advice and added $SIG{'PIPE'} = 'IGNORE'; to the top of the script.

That worked for the original crashing of the pipe and it allowed it to serve multiple images after the initial image. The problem I have now is that it randomly does or doesn't display all of the images. Some times it shows all of them, and sometimes it doesn't show one or more. All very random.

The only constant I can see is that if the print inside of the while loop doesn't fire, then no image is served. But I have no idea why sometimes it isn't getting inside of that loop and I'm not sure how to trouble shoot this..


So I'm looking for some advice or a point in a direction on how to troubleshoot this. Really at a loss on the solution here..
use strict; $SIG{'PIPE'} = 'IGNORE'; use HTTP::Daemon; use HTTP::Status; require 'C:\\rrships\\default.cgi'; my $d = HTTP::Daemon->new(Listen => 5, LocalAddr => 'localhost', LocalPort => 80, Proto => 'tcp') or die "Can't bin +d : $@\n"; # print "Please contact me at: <URL:", $d->url, ">\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { # if the below print goes, then the image is served correctl +y print $r->method . ' ' . $r->url->path . "\n"; if (($r->method eq 'GET') && ($r->url->path =~ m/\.(html|cgi +|htm|pl)/)) { my $response = HTTP::Response->new(200); $response->content(&Hello_World($r->url->path, $r->url-> +query)); $response->header("Content-Type" => "text/html"); $c->send_response($response); } elsif (($r->method eq 'GET') && ($r->url->path =~ m/\.(gif|j +pg|bmp|png)/)) { open (IMAGE, 'C:\\rrships' . $r->url->path) or warn 'Cou +ldn\'t open image: ' . $r->url->path; my $response = HTTP::Response->new(200); $response->push_header('Content-Type','image/' . $1); my $content = ''; while (<IMAGE>) { $content .= $_; } close IMAGE; $response->content($content); $c->send_response($response); } elsif (($r->method eq 'GET') && ($r->url->path eq '/')) { my $response = HTTP::Response->new(200); $response->content(&Hello_World($r->url->path, $r->url-> +query)); $response->header("Content-Type" => "text/html"); $c->send_response($response); } else { $c->send_error(RC_FORBIDDEN); } } $c->close; undef($c); }

In reply to HTTP::Daemon Pipe Breaking by bkiahg

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.