File writing-php uses fsockopen to GET the webpage, which is unsuccessful. I think fread has a problem. could you please help me?

Source: Internet
Author: User
Tags fread
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 ');

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.