<?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请求