File write-php with Fsockopen to get Web page is not successful think is fread there is a problem ask God solution

Source: Internet
Author: User
Keywords File write PHP socket Programming ping command
Tags fread
File Write Phpsocket Programming ping command

Class Http {

Const CRLF = "";

protected $fp = null;
protected $errno =-1;
Protected $errstr = ' ERROR ';
Protected $fenxi = Array ();
protected $method = ";
protected $out = ";
I don't think I need the next 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/1.1 ';
$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 down and stitch it.

Here, we deal directly with $STR.
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.