Home > Article > Backend Development > What is the system idle process? PHP simulates a socket connection once and sends data multiple times.
Copy code The 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 data 5 times 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.1rn";
$header. = "Host : {$host}rn";
$header.= "Content-type: application/x-www-form-urlencodedrn";
$header.= "Content-Length:".strlen($data). "rn";
//Keep-Alive is the key
$header.= "Connection: Keep-Alivernrn";
$header.= "{$data}rnrn";
fwrite($conn,$header);
/ /Get the result
//$result = '';
//while(!feof($conn))
//{
// $result .= fgets($conn,128);
//}
// return $result;
}
Post('127.0.0.1',80);
?>
Copy code The code is as follows:
//test.php
$ fp = fopen('result.txt','a');
$data = $_POST['user_name']." -- ". date('Y-m-d H:i:s')."rn";
fwrite ($fp,$data);
fclose($fp);
?>
The above has introduced the implementation code of what process system idle process is. PHP simulates a socket connection once and sends data multiple times, including the content of what process system idle process is. I hope it will be helpful to friends who are interested in PHP tutorials.