首页 >后端开发 >php教程 >文件写入-php用fsockopen来GET网页 就是不成功 觉得是fread那里有问题 求大神解答

文件写入-php用fsockopen来GET网页 就是不成功 觉得是fread那里有问题 求大神解答

WBOY
WBOY原创
2016-06-02 11:29:40929浏览

文件写入phpsocket编程 ping命令

class Http {

const CRLF = " ";

protected $fp = null;
受保护的 $errno = -1;
受保护的 $errstr = '错误';
受保护的 $fenxi = array();
受保护的 $method = '';
受保护的 $out = ' ';
//我觉得下面不需要两个
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;
}

}

公共函数相同($method) {
$this- >lineone[0] = $方法 . ''。 $this->fenxi['path'] . ''。 'HTTP/1.1';
$this->linetwo[0] = '主机:' . ''。 $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 "方法错误";
退出;
}
}

public function get( $str) {
//如果还要写别的东西 写在下面拼接

//这里直接处理$str
fwrite($this->fp, $str);

while (!feof($this->fp)) {
$this->out .= fread($this->fp, 1024);
echo "ok"; exit;
}

$this->show();

}

公共函数 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');

?>

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn