File: test.cgi

package info (click to toggle)
crossroads 2.65-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,664 kB
  • ctags: 355
  • sloc: cpp: 4,212; perl: 1,658; xml: 269; makefile: 186; sh: 46
file content (41 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/perl

# Simple script for benchmarking purposes. Invoke as:
#   http://whereever/test.cgi?bytes=XYZZY&usec=PLUGH
# Will spam XYZZY bytes as payload, and delay for PLUGH microsecs.
# The payload files are created in $tmpdir if they don't yet exist
# so that CPU looping is avoided.

use strict;
use Time::HiRes qw(usleep);
use CGI qw(:standard);

my $tmpdir = '/tmp';

# CGI Header
print ("Content-Type: text/plain\r\n\r\n");

# Delay for 'usec' microsecs.
my $usec = param('usec') or 0;
usleep($usec);

# Check that we have a file for the payload. If not, create it.
my $bytes = param('bytes');
my $file  = "$tmpdir/test.cgi.$bytes";
if (! -f $file) {
    open (my $of, ">$file") or die ("Cannot write $file: $!\n");
    for (my $i = 0; $i < $bytes; $i++) {
	print $of ('X');
    }
    close ($of);
}
# Send the file to the browser.
my $buf;
open (my $if, $file) or die ("Cannot read $file: $!\n");
while (sysread($if, $buf, 2048)) {
    print ($buf);
}

# All done. Return control to the web server.