file_get_contents fsocketopen分别模拟http请求

<?php
$data=array(
    'name'=>'12345',
    'title'=>'12345'
        
);
$data=http_build_query($data);
$opts=array(
    'http'=>array(
        'method'=>'POST',
        'header'=>"Content-type:application/x-www-form-urlencoded\r\nContent-Length: ".strlen($data)."\r\n",
        'content'=>$data
    )
);
$context=stream_context_create($opts);
for($i=0;$i<=10000;$i++){
    $html=file_get_contents('http://localhost/test/post.php',false,$context);

}

<?php
if(!empty($_POST)){
    mysql_connect("localhost","root","");
    mysql_query("set name utf8");
    mysql_query("use test");
    $sql='insert into test (name,title)values ("'.$_POST['name'].'","'.$_POST['title'].'")';
    echo $sql;
    if(mysql_query($sql)){
        echo "ok";
    }else{
        echo "fail";
    }
}
?>
<html>
    <body>
        <form action="" method="post">
            <input type="text" name="title"/>
            <input type="text" name="name">
            <input type="submit" value="提交">
        </form>
    </body>
</html>

create table test (
id int primary key auto_increment,
name varchar(255) not null default '',
title varchar(255) not null default ''
)engine=myisam charset=utf8;

<?php
error_reporting(E_ALL);
$data=array(
        'name'=>'12345',
        'title'=>'12345'

);
$data=http_build_query($data);
$out='';
$out.="POST http://localhost/test/post.php HTTP/1.1\r\n";
$out.="Host: localhost\r\n";
$out.="Content-type: application/x-www-form-urlencoded\r\n";
$out.='Content-Length: '.strlen($data)."\r\n\r\n";
$out.=$data."\r\n\r\n";
for($i=0;$i<=1000;$i++){
    $fp=fsockopen("localhost",80,$errno,$errstr,5000);
    fwrite($fp,$out);
}
fclose($fp);

我在本地模拟http请求


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值