Conn ($ url); $ this-& gt; same ($ this-& gt; method);} publicfunction _ destruct () {$ this-& gt; close () ;} publicfunctionconn ($ url) {$ this-& gt; fenxiparse_url ($ url); if (empty ($ this-& gt; fenxi [& #39; port & #39;]) {$ this-& gt; write the phpsocket programming ping command to the file
Class Http {
Const CRLF = "";
Protected $ fp = null;
Protected $ errno =-1;
Protected $ errstr = 'error ';
Protected $ fenxi = array ();
Protected $ method = '';
Protected $ out = '';
// I don't think we need the following two
Protected $ lineone = array ();
Protected $ linetwo = array ();
Public function _ construct ($ url ){
$ This-> conn ($ url );
// $ This-> same ($ this-> method );
}
Public function _ destruct (){
$ This-> close ();
}
Public function conn ($ url ){
$ This-> fenxi = parse_url ($ url );
If (empty ($ this-> fenxi ['port']) {
$ This-> fenxi ['port'] = 80;
}
$ This-> fp = fsockopen ($ this-> fenxi ['host'], $ this-> fenxi ['port'], $ this-> errno, $ this-> errstr, 3 );
If (! $ This-> fp ){
Echo $ this-> errstr;
}
}
Public function same ($ method ){
$ This-> lineone [0] = $ method. ''. $ this-> fenxi ['path'].''. 'HTTP/123 ';
$ This-> linetwo [0] = 'host: '.'. $ this-> fenxi ['host'];
$ Arr = array_merge ($ this-> lineone, $ this-> linetwo );
$ String = implode (self: CRLF, $ arr );
If ($ method = 'get '){
$ This-> get ($ string );
} Elseif ($ method = 'post '){
$ This-> post ($ string );
} Else {
Echo "method error ";
Exit;
}
}
Public function get ($ str ){
// If you want to write something else, write it below and splice it
// Process $ str directly here
Fwrite ($ this-> fp, $ str );
While (! Feof ($ this-> fp )){
$ This-> out. = fread ($ this-> fp, 1024 );
Echo "OK"; exit;
}
$ This-> show ();
}
Public function post ($ str ){
}
Public function close (){
Fclose ($ this-> fp );
}
Public function show (){
Echo $ this-> out;
}
}
$ Test = new Http ('http: // news.163.com/13/0613/09/9187CJ4C00014JB6.html ');
$ Test-> same ('get ');
?>