亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

php feof 特別慢

php feof 特別慢

PHP
慕妹3242003 2019-03-05 22:22:19
class Socket { protected $crlf = "\r\n"; protected $host = ''; protected $port = 80; protected $method = 'GET'; protected $path = '/'; protected $httpVersion = 'HTTP/1.1'; protected $headers = array(); protected $body = ''; protected $error = array(); protected $timeout = 5; public function url($url) { $info = parse_url($url); $this->host = $info['host']; isset($info['path']) && $this->path = $info['path']; isset($info['port']) && $this->port = $info['port']; return $this; } public function method($method) { $this->method = $method; return $this; } public function path($path) { $this->path = $path; return $this; } public function httpVersion($version) { $this->httpVersion = $version; return $this; } public function host($host) { $this->host = $host; return $this; } public function header($header) { $this->headers[] = $header; return $this; } public function body($body) { $this->body = $body; return $this; } public function send() { $handle = fsockopen($this->host, $this->port, $this->error['errno'], $this->error['errstr'], $this->timeout); $req = join($this->crlf, array_merge( array("{$this->method} {$this->path} {$this->httpVersion}"), array("Host: {$this->host}"), $this->headers, array(''), array($this->body), array('') )); fwrite($handle, $req); $res = ''; while ( !feof($handle) ) { $res .= fread($handle, 1024); } fclose($handle); return $res; } } $s = new Socket(); var_dump( $s->url('http://baidu.com')->send() ); send()方法里的while特別慢,如果只是調用fread($handle, 1024),速度很快,朋友們看看什么情況???
查看完整描述

1 回答

?
慕絲7291255

TA貢獻1859條經驗 獲得超6個贊

這個!feof($handle) 條件 一直成立 所以一直在循環 所以慢,你單獨調用fread($handle, 1024) 只執行一次當然快

查看完整回答
反對 回復 2019-03-18
  • 1 回答
  • 0 關注
  • 440 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號