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 ');
?>