pengwn has asked for the wisdom of the Perl Monks concerning the following question:
But is superfast with the below codesub httpserv { my $socket = shift; my $buf; while(defined($buf = <$socket>)) { # nothing } print $socket "HTTP/1.0 200 OK\n"; print $socket "Cache-Control: no-cache \n"; print $socket "Server: Apache/2.2.23(Fedora)\n"; print $socket "Connection: close \n"; print $socket "Content-Type: text/html; charset=UTF-8\n"; print $socket "\n\n"; # Without this browser doesn't show H +TML Content print $socket "<HTML><HEAD><TITLE>\n"; print $socket "Got your message</TITLE></HEAD>\n"; print $socket "<BODY>Got your message</BODY></HTML>\n"; $socket->close(); }
Observe the last; in the while loop.sub httpserv { my $socket = shift; my $buf; while(defined($buf = <$socket>)) { last; # Without this it is like removing a +utoflush(1), # Without the "last;" the client conn +ection hangs; } print $socket "HTTP/1.0 200 OK\n"; print $socket "Cache-Control: no-cache \n"; print $socket "Server: Apache/2.2.23(Fedora)\n"; print $socket "Connection: close \n"; print $socket "Content-Type: text/html; charset=UTF-8\n"; print $socket "\n\n"; # Without this browser doesn't show H +TML Content print $socket "<HTML><HEAD><TITLE>\n"; print $socket "Got your message</TITLE></HEAD>\n"; print $socket "<BODY>Got your message</BODY></HTML>\n"; $socket->close(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: what's with last;
by Corion (Patriarch) on Dec 30, 2007 at 21:23 UTC | |
|
Re: what's with last;
by jasonk (Parson) on Dec 30, 2007 at 21:20 UTC | |
|
Re: what's with last;
by NetWallah (Canon) on Dec 31, 2007 at 16:29 UTC | |
|
Re: what's with last;
by pengwn (Acolyte) on Jan 02, 2008 at 21:03 UTC |