public function write($arAllVars, $baseDir, $initDir, $filename, $TTL) { $documentRoot = \Bitrix\Main\Application::getDocumentRoot(); $fn = IO\Path::combine($documentRoot, $baseDir, $initDir, $filename); $file = new IO\File($fn); $fnTmp = IO\Path::combine($documentRoot, $baseDir, $initDir, md5(mt_rand()) . ".tmp"); $fileTmp = new IO\File($fnTmp); $dir = $file->getDirectory(); if (!$dir->isExists()) { $dir->create(); } 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) . "';"; $v = serialize($arAllVars); if (static::checkZeroDanger()) { $v = str_replace("*", "", $v); $contents .= "\n\$zeroDanger = true;"; } $contents .= "\n\$ser_content = '" . str_replace("'", "\\'", str_replace("\\", "\\\\", $v)) . "';"; $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 = $fileTmp->putContents($contents); $len = \Bitrix\Main\Text\String::strlenBytes($contents); //This checks for Zend Server CE in order to supress warnings if (function_exists('accelerator_reset')) { try { $file->delete(); } catch (\Exception $ex) { } } elseif ($file->isExists()) { $file->delete(); } if ($this->written === $len) { $fileTmp->rename($fn); } //This checks for Zend Server CE in order to supress warnings if (function_exists('accelerator_reset')) { try { IO\File::deleteFile($fnTmp); } catch (\Exception $ex) { } } elseif (IO\File::isFileExists($fnTmp)) { IO\File::deleteFile($fnTmp); } }
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::strlenBytes($contents); fclose($handle); static::unlink($fn); if ($this->written === $len) { rename($fnTmp, $fn); } static::unlink($fnTmp); } }