Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /usr/share/doc/perl-Mojolicious/examples/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/perl-Mojolicious/examples/microhttpd.pl
#
# Minimal event loop example demonstrating how to cheat at HTTP benchmarks :)
#
use Mojo::Base -strict;
use Mojo::IOLoop;

my %buffer;
Mojo::IOLoop->server(
  {port => 8080} => sub {
    my ($loop, $stream, $id) = @_;
    $stream->on(
      read => sub {
        my ($stream, $chunk) = @_;

        # Check if we got start-line and headers (no body support)
        $buffer{$id} .= $chunk;
        if (index($buffer{$id}, "\x0d\x0a\x0d\x0a") >= 0) {
          delete $buffer{$id};

          # Write a minimal HTTP response
          # (the "Hello World!" message has been optimized away!)
          $stream->write(
            "HTTP/1.1 200 OK\x0d\x0aContent-Length: 0\x0d\x0a\x0d\x0a");
        }
      }
    );
  }
);

print <<'EOF';
Starting server on port 8080.
For testing use something like "wrk -c 100 -d 10s http://127.0.0.1:8080/".
EOF

# Stop gracefully to make profiling easier
Mojo::IOLoop->recurring(1 => sub { });
local $SIG{INT} = local $SIG{TERM} = sub { Mojo::IOLoop->stop };
Mojo::IOLoop->start;

1;

Hry