Leser: 22
2010-05-28T18:15:54 esskarOder auch schonmal ein 100 Continue schicken
2010-05-28T19:37:10 esskarmit CGI gehts wohl nicht, der server wird alles, was du azf STDOUT raushaust, als body nehmen.
2010-05-29T14:01:12 bianca2010-05-28T19:37:10 esskarmit CGI gehts wohl nicht, der server wird alles, was du azf STDOUT raushaust, als body nehmen.
Ja, hab ich auch festgestellt.
2010-05-29T20:17:52 esskardeswegen nehme ich jetzt an, dass wenn du
HTTP/1.x 100 Continue raushaust, dass nach dem 200 OK kommt, also zu spät und falsch
QuoteUSING NPH SCRIPTSUSING NPH SCRIPTS
NPH, or "no-parsed-header", scripts bypass the server completely by sending the complete HTTP header directly to the browser.
CGI qw(:standard -nph);
CGI->nph(1);
print header(-nph=>1);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
b0
<html>
<head>
</head>
<body>
<p> Bin DA!
<form action="test_keepalive.pl" method="post">
<input type="submit" value="Nochmal!">
</form>
</p>
</body>
</html>
0
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#!/usr/bin/perl -W use strict; use warnings; use IO::Handle; STDOUT -> autoflush (1); # sicherheitshalber statt $| = 1; gem. [msg://133383] use CGI; my $q = CGI -> new; (my $script = $0) =~ s/^.*[\\\/]//g; if (defined $q -> param ('action') && defined $q -> param ('sekunden')) { my $header = $q -> header; if ($q -> param ('action') eq 'start1') { sleep $q -> param ('sekunden'); } elsif ($q -> param ('action') eq 'start3') { $q -> nph (1); # no-parsed-header Modus (Header wird vom Script gesendet) sleep $q -> param ('sekunden'); $header = "Status: 100 Continue\n$header"; } else { print $header; for (my $z = 0; $z < $q -> param ('sekunden'); $z ++) { print " \n"; sleep 1; } $header = ''; } print <<HTML_TEIL; $header <html> <head> </head> <body> <p> Bin DA! <form action="$script" method="post"> <input type="submit" value="Nochmal!"> </form> </p> </body> </html> HTML_TEIL } else { print $q -> header . <<HTML_TEIL; <html> <head> </head> <body> <p> <form action="$script" method="post"> <select name="action"> <option value="start1">Test 1 (einfaches sleep)</option> <option value="start2">Test 2 (Schleife mit Blank pro Sekunde)</option> <option value="start3">Test 3 (mit eigenem Header)</option> </select><br> Anzahl Sekunden: <input type="text" name="sekunden"><br> <input type="submit" value="Start"> </form> </p> </body> </html> HTML_TEIL }
HTTP/1.1 100 Continue
2010-05-30T15:06:24 GwenDragonLass doch mal dein Skript auf der Kommandozueile ablaufen, dann siehst du was es ausgibt.
2010-05-28T17:58:50 biancaHabe ein Script, dass mittels system() einen bis zu 60 Sekunden dauernden Befehl ausführt. Erst nach Abschluss des Befehls werden Header und Inhalt zum Browser gesendet.
2010-05-30T13:03:55 pqmache ein fork und führe im child das programm aus, im parent schickst du dem browser eine refresh-seite, mit der du alle 5 sekunden nachguckst, ob dein geforkter prozess schon fertig ist.
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
#!/usr/bin/perl -W use strict; use warnings; use IO::Handle; STDOUT -> autoflush (1); # sicherheitshalber statt $| = 1; use Digest::MD5 qw (md5_hex); use CGI qw (:push); my $q = CGI -> new; (my $script = $0) =~ s/^.*[\\\/]//g; if (defined $q -> param ('action') && defined $q -> param ('sekunden')) { my $header = $q -> header; if ($q -> param ('action') eq 'start1') { sleep $q -> param ('sekunden'); } elsif ($q -> param ('action') eq 'start3') { CGI -> nph (1); # no-parsed-header Modus (Header wird vom Script gesendet) print multipart_init (-boundary => '----here we go!'); sleep $q -> param ('sekunden'); # $header = "Status: 100 Continue\n$header"; # funktioniert (noch) nicht } elsif ($q -> param ('action') eq 'start4') { if (defined $q -> param ('warte') && $q -> param ('warte') ne '') { if (-f $q -> param ('warte')) { print $header . 'fertig'; exit (); } else { print $header . 'hold'; exit (); } } else { my $datei = md5_hex ($ENV{'REMOTE_ADDR'},$ENV{'REMOTE_PORT'},time,ZUFALL(),$$); if (my $pid = fork ()) { # Vater print <<HTML_TEIL; $header <html> <head> </head> <body> <p><div id="status">Arbeit an Datei $datei läuft, bitte warten</div></p> <script type="text/javascript"> function getXmlObject() { var http_request; if (window.XMLHttpRequest) { http_request = new XMLHttpRequest(); } else if (window.ActiveXObject) { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } return http_request; } function ajax_request () { var http_request = getXmlObject(); http_request.onreadystatechange = function() { try { if (http_request.readyState == 4) { if (http_request.status == 200) { if (http_request.responseText == 'hold') { document.getElementById('status').innerHTML += '.'; window.setTimeout(ajax_request,1000); } else { document.getElementById('status').innerHTML += '<br>FERTIG!'; } } } } catch(e) {} }; http_request.open("POST","$script",true); http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=ISO-8859-1'); http_request.send("action=start4&sekunden=0&warte=$datei"); } ajax_request (); </script> </body> </html> HTML_TEIL exit (); # /Vater } else { # Sohn sleep $q -> param ('sekunden'); open (my $fh,">$datei"); print $fh "test"; exit (); # /Sohn } } sub ZUFALL { srand (time ^ $$); my $pw = ''; my @atoms = ('a'..'z', 'A'..'Z' ,0..9); until ( length($pw) == 12) { $pw .= $atoms[rand scalar @atoms] } return $pw; } } else { print $header; for (my $z = 0; $z < $q -> param ('sekunden'); $z ++) { print " \n"; sleep 1; } $header = ''; } print <<HTML_TEIL; $header <html> <head> </head> <body> <p> Bin DA! <form action="$script" method="post"> <input type="submit" value="Nochmal!"> </form> </p> </body> </html> HTML_TEIL } else { print $q -> header . <<HTML_TEIL; <html> <head> </head> <body> <p> <form action="$script" method="post"> <select name="action"> <option value="start1">Test 1 (einfaches sleep)</option> <option value="start2">Test 2 (Schleife mit Blank pro Sekunde)</option> <option value="start3">Test 3 (mit eigenem Header)</option> <option value="start4">Test 4 (mit Ajax Warteseite)</option> </select><br> Anzahl Sekunden: <input id="sekinp" type="text" name="sekunden"><br> <input type="submit" value="Start"> </form> </p> </body> </html> HTML_TEIL }