好久没写php了,突然做个实验,发现竟然没有日志,哎
<?phpdefined('API') or exit('Access Denied');class Log{ private $FilePath; private $FileName; private $m_MaxLogFileNum; private $m_RotaType; private $m_RotaParam; private $m_InitOk; private $m_Priority; private $m_LogCount; const EMERG = 0; const FATAL = 0; const ALERT = 100; const CRIT = 200; const ERROR = 300; const WARN = 400; const NOTICE = 500; const INFO = 600; const DEBUG = 700; const LOG_SUFFIXED = ".log.txt"; const DEFAULT_ROTE = 5242880; /** * @abstract 初始化 * @param String $dir 文件路径 * @param String $filename 文件名 * @return */ public function __construct($dir, $filename, $priority = Log::INFO, $maxlogfilenum = 3, $rotatype = 1, $rotaparam = LOG::DEFAULT_ROTE) { $dot_offset = strpos($filename, "."); if ($dot_offset !== false) $this->FileName = substr($filename,0, $dot_offset); else $this->FileName = $filename; $this->FilePath = $dir; $this->m_MaxLogFileNum = intval($maxlogfilenum); $this->m_RotaParam = intval($rotaparam); $this->m_RotaType = intval($rotatype); $this->m_Priority = intval($priority); $this->m_LogCount = 0; $this->m_InitOk = $this->InitDir(); umask(0000); $path=$this->createPath($this->FilePath,$this->FileName); if(!$this->isExist($path)) { if(!$this->createDir($this->FilePath)) { #echo("创建目录失败!"); } if(!$this->createLogFile($path)){ #echo("创建文件失败!"); } } } private function createPath($dir,$file) { $file = fopen($dir.DIRECTORY_SEPARATOR.$file,'w'); if($file) { fclose($file); } return $dir.DIRECTORY_SEPARATOR.$file; } private function InitDir() { if (is_dir($this->FilePath) === false) { if(!$this->createDir($this->FilePath)) { //echo("创建目录失败!"); //throw exception return false; } } return true; } function console($priority, $log) { if ($this->m_InitOk == false) return; if ($priority > $this->m_Priority) return; $path = $this->getLogFilePath($this->FilePath, $this->FileName).Log::LOG_SUFFIXED; $handle= fopen($path,"a+"); if ($handle === false) { return; } $datestr = strftime("%Y-%m-%d %H:%M:%S "); $caller_info = $this->get_caller_info(); $status = fwrite($handle, $caller_info.$datestr.$log."\n"); if(!$status){//写日志失败 echo("写入日志失败"); } fclose($handle); $this->RotaLog(); } /** * @abstract 写入日志 * @param String $log 内容 */ function setLog($log) { $this->console(Log::NOTICE, $log); } function LogDebug($log) { $this->console(Log::DEBUG, $log); } function LogError($log) { $this->console(Log::ERROR, $log); } function LogNotice($log) { $this->console(Log::NOTICE, $log); } private function get_caller_info() { $ret = debug_backtrace(); foreach ($ret as $item) { if(isset($item['class']) && 'Logs' == $item['class']) { continue; } $file_name = basename($item['file']); return <<<S {$file_name}:{$item['line']} S; } } private function RotaLog() { $file_path = $this->getLogFilePath($this->FilePath, $this->FileName).LOG::LOG_SUFFIXED; if ($this->m_LogCount%10==0) clearstatcache(); ++$this->m_LogCount; $file_stat_info = stat($file_path); if ($file_stat_info === FALSE) return; if ($this->m_RotaType != 1) return; //echo "file: ".$file_path." vs ".$this->m_RotaParam."\n"; if ($file_stat_info['size'] < $this->m_RotaParam) return; $raw_file_path = $this->getLogFilePath($this->FilePath, $this->FileName); $file_path = $raw_file_path.($this->m_MaxLogFileNum - 1).LOG::LOG_SUFFIXED; //echo "lastest file:".$file_path."\n"; if ($this->isExist($file_path)) { unlink($file_path); } for ($i = $this->m_MaxLogFileNum - 2; $i >= 0; $i--) { if ($i == 0) $file_path = $raw_file_path.LOG::LOG_SUFFIXED; else $file_path = $raw_file_path.$i.LOG::LOG_SUFFIXED; if ($this->isExist($file_path)) { $new_file_path = $raw_file_path.($i+1).LOG::LOG_SUFFIXED; if (rename($file_path, $new_file_path) < 0) { continue; } } } } function isExist($path){ return file_exists($path); } /** * @abstract 创建目录 * @param <type> $dir 目录名 * @return bool */ function createDir($dir){ //判断目录是否存在 return is_dir($dir) or ($this->createDir(dirname($dir)) and mkdir($dir, 0777)); } /** * @abstract 创建日志文件 * @param String $path * @return bool */ function createLogFile($path){ $handle=fopen($path,"w"); //创建文件 if($handle) { fclose($handle); } return $this->isExist($path); } /** * @abstract 创建路径 * @param String $dir 目录名 * @param String $filename */ function getLogFilePath($dir,$filename){ return $dir."/".$filename; }}?>

Laravel使用其直觀的閃存方法簡化了處理臨時會話數據。這非常適合在您的應用程序中顯示簡短的消息,警報或通知。 默認情況下,數據僅針對後續請求: $請求 -

PHP日誌記錄對於監視和調試Web應用程序以及捕獲關鍵事件,錯誤和運行時行為至關重要。它為系統性能提供了寶貴的見解,有助於識別問題並支持更快的故障排除

PHP客戶端URL(curl)擴展是開發人員的強大工具,可以與遠程服務器和REST API無縫交互。通過利用Libcurl(備受尊敬的多協議文件傳輸庫),PHP curl促進了有效的執行

Laravel 提供简洁的 HTTP 响应模拟语法,简化了 HTTP 交互测试。这种方法显著减少了代码冗余,同时使您的测试模拟更直观。 基本实现提供了多种响应类型快捷方式: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

您是否想為客戶最緊迫的問題提供實時的即時解決方案? 實時聊天使您可以與客戶進行實時對話,並立即解決他們的問題。它允許您為您的自定義提供更快的服務

文章討論了PHP 5.3中介紹的PHP中的晚期靜態結合(LSB),允許靜態方法的運行時間分辨率調用以更靈活的繼承。 LSB的實用應用和潛在的觸摸


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

Dreamweaver Mac版
視覺化網頁開發工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

SublimeText3 Linux新版
SublimeText3 Linux最新版