您好,欢迎访问一九零五行业门户网

文件写入-php 用fsockopen来GET网页 感觉死循环了 最后30秒超时 感觉是fread的问题 求大神解答

文件写入phpsocket网络编程
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) {
//如果还要写别的东西 写在下面拼接
//这里直接处理$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');
?>
其它类似信息

推荐信息