php模擬socket一次連接,多次發(fā)送數(shù)據(jù)的實現(xiàn)代碼
更新時間:2011年07月26日 00:11:19 作者:
php模擬socket一次連接,多次發(fā)送數(shù)據(jù)的實現(xiàn)代碼,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:
<?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);
?>
復(fù)制代碼 代碼如下:
<?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);
?>
您可能感興趣的文章:
- 解析:通過php socket并借助telnet實現(xiàn)簡單的聊天程序
- 基于PHP Socket配置以及實例的詳細(xì)介紹
- 深入php socket的講解與實例分析
- 基于php socket(fsockopen)的應(yīng)用實例分析
- PHP異步調(diào)用socket實現(xiàn)代碼
- php空間不支持socket但支持curl時recaptcha的用法
- php獲取遠程圖片的兩種 CURL方式和sockets方式獲取遠程圖片
- php中使用Curl、socket、file_get_contents三種方法POST提交數(shù)據(jù)
- php HandlerSocket的使用
- PHP Socket 編程
- php win下Socket方式發(fā)郵件類
- php socket方式提交的post詳解
- PHP實現(xiàn)Socket服務(wù)器的代碼
- 在PHP中使用Sockets 從Usenet中獲取文件
- 在php中使用sockets:從新聞組中獲取文章
- 使用php通過Socket進行發(fā)信源碼,支持發(fā)信認(rèn)證
- PHP SOCKET 技術(shù)研究
- 淺析PHP Socket技術(shù)
相關(guān)文章
php strrpos()與strripos()函數(shù)
以下是對php中的strrpos函數(shù)與strripos函數(shù)的用法進行了詳細(xì)的介紹,需要的朋友可以過來參考下2013-08-08
php 數(shù)學(xué)運算驗證碼實現(xiàn)代碼
php 數(shù)學(xué)運算驗證碼實現(xiàn)代碼2009-10-10

