文件写入-php用fsockopen来GET网页感觉死循环了最后30秒超时感觉是fread的问题求大神解答
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了文件写入-php用fsockopen来GET网页感觉死循环了最后30秒超时感觉是fread的问题求大神解答,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1483字,纯文字阅读大概需要3分钟。
内容图文
![文件写入-php用fsockopen来GET网页感觉死循环了最后30秒超时感觉是fread的问题求大神解答](/upload/InfoBanner/zyjiaocheng/246/3b0311b1ade84f0c98ad7744ebd518af.jpg)
class Http {
const CRLF = " ";
protected $fp = null;
protected $errno = -1;
protected $errstr = 'error';
protected $fenxi = array();
protected $method = '';
protected $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;
}
}
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');
?>
内容总结
以上是互联网集市为您收集整理的文件写入-php用fsockopen来GET网页感觉死循环了最后30秒超时感觉是fread的问题求大神解答全部内容,希望文章能够帮你解决文件写入-php用fsockopen来GET网页感觉死循环了最后30秒超时感觉是fread的问题求大神解答所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。