Copy CodeThe code is as follows:
post.php
function Post ($host, $port)
{
$host = "127.0.0.1";
Establish a connection
$conn = Fsockopen ($host, $port);
if (! $conn)
{
Die ("Con error");
}
Send 5 data in a loop
//
for ($i = 0; $i <5; $i + +)
{
$data = "User_name=admin". $i;
WriteData ($conn, $host, $data);
echo $i. "
";
}
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 is the key
$header. = "connection:keep-alive\r\n\r\n";
$header. = "{$data}\r\n\r\n";
Fwrite ($conn, $header);
Fetch results
$result = ";
while (!feof ($conn))
//{
$result. = Fgets ($conn, 128);
//}
return $result;
}
Post (' 127.0.0.1 ', 80);
?>
Copy the Code code as follows:
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);
?>
The above describes what the system Idle process is, PHP simulates a socket connection, the implementation code that sends the data multiple times, including what the system Idle process is, and hopefully a friend interested in the PHP tutorial will be helpful.