public function handelStaticFile($requestUrl, \swoole_http_response $respone) { $filename = Angel::app()->basePath . $requestUrl; if (is_file($filename)) { $mimeType = FileHelper::getMimeType($filename); if (empty($mimeType)) { $mimeType = 'text/html'; } $laseModifyTime = @filemtime($filename); if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $laseModifyTime) { $respone->status(304); Angel::app()->endend(); } else { if (filesize($filename) > self::MIN_GZIP_SIZE) { $respone->gzip(); } $respone->header('Content-Type', $mimeType); $respone->header('last-modified', $laseModifyTime); swoole_async_read($filename, function ($filename, $content) use($respone) { Angel::app()->end($content); }); } return true; } return false; }
protected function setValue($key, $value, $duration) { $this->gc(); $cacheFile = $this->getCacheFile($key); if ($this->directoryLevel > 0) { @FileHelper::createDirectory(dirname($cacheFile), $this->dirMode, true); } if (@file_put_contents($cacheFile, $value, LOCK_EX) !== false) { if ($this->fileMode !== null) { @chmod($cacheFile, $this->fileMode); } if ($duration <= 0) { $duration = 31536000; // 1 year } return @touch($cacheFile, $duration + time()); } else { $error = error_get_last(); return false; } }
/** * init runtime environment */ protected function initEnvironment() { if (!is_writable($this->runtimePath)) { throw new Exception("{$this->runtimePath} is not writable"); } if (!is_dir($this->runtimePath)) { FileHelper::createDirectory($this->runtimePath); } }