function SetPos($iCurPos = 0) { $iCurPos = intval($iCurPos); if ($iCurPos <= $this->iFileLength) { $this->iCurPos = $iCurPos; } else { $this->iCurPos = $this->iFileLength; } $pos = $this->iCurPos; if ($this->__hasBOM) { $pos += 3; } fseek($this->__file, $pos); if (feof($this->__file)) { $this->__buffer = ""; } else { $this->__buffer = fread($this->__file, 1024 * 1024); } $this->__buffer_size = String::getBinaryLength($this->__buffer); $this->__buffer_pos = 0; }
public function write($arAllVars, $baseDir, $initDir, $filename, $TTL) { $documentRoot = Main\Loader::getDocumentRoot(); $folder = $documentRoot . "/" . ltrim($baseDir . $initDir, "/"); $fn = $folder . $filename; $fnTmp = $folder . md5(mt_rand()) . ".tmp"; if (!CheckDirPath($fn)) { return; } if ($handle = fopen($fnTmp, "wb+")) { if (is_array($arAllVars)) { $contents = "<?"; $contents .= "\nif(\$INCLUDE_FROM_CACHE!='Y')return false;"; $contents .= "\n\$datecreate = '" . str_pad(mktime(), 12, "0", STR_PAD_LEFT) . "';"; $contents .= "\n\$dateexpire = '" . str_pad(mktime() + intval($TTL), 12, "0", STR_PAD_LEFT) . "';"; $contents .= "\n\$ser_content = '" . str_replace("'", "\\'", str_replace("\\", "\\\\", serialize($arAllVars))) . "';"; $contents .= "\nreturn true;"; $contents .= "\n?>"; } else { $contents = "BX" . str_pad(mktime(), 12, "0", STR_PAD_LEFT) . str_pad(mktime() + intval($this->TTL), 12, "0", STR_PAD_LEFT); $contents .= $arAllVars; } $this->written = fwrite($handle, $contents); $this->path = $fn; $len = Main\Text\String::getBinaryLength($contents); fclose($handle); static::unlink($fn); if ($this->written === $len) { rename($fnTmp, $fn); } static::unlink($fnTmp); } }
protected function readResponse() { $headers = ""; while (!feof($this->resource)) { $line = fgets($this->resource, self::BUF_READ_LEN); if ($line == "\r\n" || $line === false) { break; } $headers .= $line; if ($this->streamTimeout > 0) { $info = stream_get_meta_data($this->resource); if ($info['timed_out']) { break; } } } $this->parseHeaders($headers); if ($this->redirect && ($location = $this->responseHeaders->get("Location")) !== null && $location != '') { //do we need entity body on redirect? return; } if ($this->responseHeaders->get("Transfer-Encoding") == "chunked") { while (!feof($this->resource)) { /* chunk = chunk-size [ chunk-extension ] CRLF chunk-data CRLF chunk-size = 1*HEX chunk-extension = *( ";" chunk-ext-name [ "=" chunk-ext-val ] ) */ $line = fgets($this->resource, self::BUF_READ_LEN); if ($line == "\r\n") { continue; } if (($pos = strpos($line, ";")) !== false) { $line = substr($line, 0, $pos); } $length = hexdec($line); while ($length > 0) { $buf = $this->receive($length); if ($buf === false) { break 2; } $length -= String::getBinaryLength($buf); if ($this->streamTimeout > 0) { $info = stream_get_meta_data($this->resource); if ($info['timed_out']) { break 2; } } } } } else { while (!feof($this->resource)) { $buf = $this->receive(); if ($buf === false) { break; } if ($this->streamTimeout > 0) { $info = stream_get_meta_data($this->resource); if ($info['timed_out']) { break; } } } } if ($this->responseHeaders->get("Content-Encoding") == "gzip") { $this->decompress(); } }