• php模拟socket一次连接,多次发送数据的实现


    简介:这是php模拟socket一次连接,多次发送数据的实现的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。

    class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=340844' scrolling='no'>
    <?php 
    //post.php
    function Post($host,$port)
    {
    //$host="127.0.0.1";
    //建立连接
    $conn = fsockopen($host,$port);
    if (!$conn)
    {
    die("Con error");
    }
    //循环发送5次数据
    //
    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是关键
    $header.= "Connection: Keep-Alive\r\n\r\n";
    $header.= "{$data}\r\n\r\n";

    fwrite($conn,$header);

    //取结果
    //$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);
    ?>

    转自:csdn

    爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具

    http://biancheng.dnbcw.info/php/340844.html pageNo:6
  • 相关阅读:
    TCL 双引号和花括号的区别
    在Vivado中调用ModelSim生成FSM的状态转移图
    基于配置文件的方式来配置AOP
    Spring MVC_Hello World
    重用切点表达式
    Spring MVC概述(2)
    Shiro_DelegatingFilterProxy
    Shiro-工作流程
    切面的优先级
    Shiro-集成Spring
  • 原文地址:https://www.cnblogs.com/ooooo/p/2243928.html
Copyright © 2020-2023  润新知