System Idle process is the implementation code of what processes PHP simulates a socket connection, sending data multiple times

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.