<?php
//interfaces for HTTP request ClassesInterfaceProto {//Connection URLfunction conn ($url); //send a Get queryfunctionGet(); //Send post Queryfunction post (); //Close Connectionfunction Close ();}classHttp implements Proto {ConstCRLF ="\ r \ n"; protected$errno =-1; protected$errstr ="'; protected$response ="'; protected$url =NULL; protected$version ='http/1.1'; protected$FH =NULL; protected$line =Array (); protected$header =Array (); protected$body =Array (); Publicfunction __construct ($url) {$ This-Conn ($url); $ This->setheader ('Host:'. $ This->url['Host']); } //This method is responsible for writing the request line protectedfunction Setline ($method) {$ This->line[0] = $method.' '. $ This->url['Path'] .' '. $ This-version; } //This method is responsible for writing header information protectedfunction SetHeader ($headerline) {$ This->header[] =$headerline; } //This method is responsible for writing the principal information protectedfunction Setbody ($body) {$ This->body[] =http_build_query ($body); } //Connection URL Publicfunction Conn ($url) {$ This->url =Parse_url ($url); //Determine the port if(!isset ($ This->url['Port'])) { $ This->url['Port'] = the; } $ This->FH = Fsockopen ($ This->url['Host'],$ This->url['Port'],$ This->errno,$ This->ERRSTR,3); } //constructing data for GET requests PublicfunctionGet() { $ This->setline ('GET'); $ This-request (); return$ This-response; } //constructing data for a post query Publicfunction post ($body =Array ()) { $ This->setline ('POST'); //Design Content-type$ This->setheader ('content-type:application/x-www-form-urlencoded'); //design body information, which is different than get$ This-setbody ($body); //Calculate Content-length$ This->setheader ('content-length:'. Strlen ($ This->body[0])); $ This-request (); } //really request Publicfunction Request () {//Put the request line, header information, entity information in an array, easy to splice$req = Array_merge ($ This->line,$ This->header,array ("'),$ This->body,array ("')); //Print_r ($req);$req=implode (SELF::CRLF, $req); //echo $req; exit;fwrite ($ This-FH, $req); while(!feof ($ This-FH)) { $ This->response. = Fread ($ This->FH,1024x768); } $ This->close ();//Close Connection } //Close Connection Publicfunction Close () {fclose ($ This-FH); } }
Set_time_limit (0);
$url = ' http://xxxxx.net.cn/0523/? ';
for ($i =1; $i <100; $i + +) {
$str = Str_shuffle (' abcdefghijklmnopqrst0776656 ');
$tit = substr ($str, 0,5);
$con = substr ($str, 6,8);
$http = new http ($url);
$http->post (' tit ' = ' + $tit, ' con ' + $con, ' submit ' + ' message '));
echo $tit, '-----------', $con, ' <br/> ';
Usleep (2000);
}
Http+socket Programming Bulk posting