亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

php模擬socket一次連接,多次發(fā)送數(shù)據(jù)的實現(xiàn)代碼

 更新時間:2011年07月26日 00:11:19   作者:  
php模擬socket一次連接,多次發(fā)送數(shù)據(jù)的實現(xiàn)代碼,需要的朋友可以參考下。
復制代碼 代碼如下:

<?php
//post.php
function Post($host,$port)
{
//$host="127.0.0.1";
//建立連接
$conn = fsockopen($host,$port);
if (!$conn)
{
die("Con error");
}
//循環(huán)發(fā)送5次數(shù)據(jù)
//
for($i = 0;$i<5;$i++)
{
$data="user_name=admin".$i;
WriteData($conn,$host,$data);
echo $i."<br />";
}
fclose($conn);
}
function WriteData($conn,$host,$data)
{
$header = "POST /test.php HTTP/1.1\r\n";
$header.= "Host : {$host}\r\n";
$header.= "Content-type: application/x-www-form-urlencoded\r\n";
$header.= "Content-Length:".strlen($data)."\r\n";
//Keep-Alive是關(guān)鍵
$header.= "Connection: Keep-Alive\r\n\r\n";
$header.= "{$data}\r\n\r\n";
fwrite($conn,$header);
//取結(jié)果
//$result = '';
//while(!feof($conn))
//{
// $result .= fgets($conn,128);
//}
//return $result;
}
Post('127.0.0.1',80);
?>

復制代碼 代碼如下:

<?php
//test.php
$fp = fopen('result.txt','a');
$data = $_POST['user_name']." -- ". date('Y-m-d H:i:s')."\r\n";
fwrite($fp,$data);
fclose($fp);
?>

相關(guān)文章

最新評論