這是我的程式碼:
<code><?php /** * User: mh * Date: 2016/9/9 * Time: 19:12 */ namespace Session; use SessionHandlerInterface; class RedisSession implements SessionHandlerInterface { private $redis; // 连接Redis private function connect() { if(!$this->redis) { $cfg = [ 'scheme' => env('REDIS_SCHEME', 'tcp'), 'host' => env('REDIS_HOST', '127.0.0.1'), 'port' => env('REDIS_PORT', 6379) ]; $this->redis = new \Predis\Client($cfg); } } /** * Close the session * @since 5.4.0 */ public function close() { return true; } /** * Destroy a session * @return boolean * @since 5.4.0 */ public function destroy($session_id) { $this->connect(); $this->redis->del($session_id); return true; } /** * Cleanup old sessions * @return boolean * @since 5.4.0 */ public function gc($maxlifetime) { return true; } /** * Initialize session * @since 5.4.0 */ public function open($save_path, $sessionName) { return true; } /** * Read session data * @return string * @since 5.4.0 */ public function read($session_id) { $this->connect(); if($this->redis->exists($session_id)) { $value = $this->redis->get($session_id); return $value ? ($value) : ''; } else { $expire = configure('Ymf.Account.expire'); $this->redis->setex($session_id, $expire, ''); return ''; } return ''; } /** * Write session data * @return boolean * @since 5.4.0 */ public function write($session_id, $sessionData) { $this->connect(); file_put_contents(__DIR__ . '/../../write.log', "写入{$sessionData}\r\n", FILE_APPEND); if($this->redis->set("flf", "hfl")) { return true; } else { return false; } } }</code>
排查只會,發現這個$this->redis->set方法特別慢,什麼原因。 。 。 。
回覆內容:
這是我的程式碼:
<code><?php /** * User: mh * Date: 2016/9/9 * Time: 19:12 */ namespace Session; use SessionHandlerInterface; class RedisSession implements SessionHandlerInterface { private $redis; // 连接Redis private function connect() { if(!$this->redis) { $cfg = [ 'scheme' => env('REDIS_SCHEME', 'tcp'), 'host' => env('REDIS_HOST', '127.0.0.1'), 'port' => env('REDIS_PORT', 6379) ]; $this->redis = new \Predis\Client($cfg); } } /** * Close the session * @since 5.4.0 */ public function close() { return true; } /** * Destroy a session * @return boolean * @since 5.4.0 */ public function destroy($session_id) { $this->connect(); $this->redis->del($session_id); return true; } /** * Cleanup old sessions * @return boolean * @since 5.4.0 */ public function gc($maxlifetime) { return true; } /** * Initialize session * @since 5.4.0 */ public function open($save_path, $sessionName) { return true; } /** * Read session data * @return string * @since 5.4.0 */ public function read($session_id) { $this->connect(); if($this->redis->exists($session_id)) { $value = $this->redis->get($session_id); return $value ? ($value) : ''; } else { $expire = configure('Ymf.Account.expire'); $this->redis->setex($session_id, $expire, ''); return ''; } return ''; } /** * Write session data * @return boolean * @since 5.4.0 */ public function write($session_id, $sessionData) { $this->connect(); file_put_contents(__DIR__ . '/../../write.log', "写入{$sessionData}\r\n", FILE_APPEND); if($this->redis->set("flf", "hfl")) { return true; } else { return false; } } }</code>
排查只會,發現這個$this->redis->set方法特別慢,什麼原因。 。 。 。

本文討論了PHP中的crypt()和password_hash()的差異,以進行密碼哈希,重點介紹其實施,安全性和對現代Web應用程序的適用性。

文章討論了通過輸入驗證,輸出編碼以及使用OWASP ESAPI和HTML淨化器之類的工具來防止PHP中的跨站點腳本(XSS)。

自動加載PHP會在需要時自動加載類文件,從而通過減少內存使用和增強代碼組織來提高性能。最佳實踐包括使用PSR-4和有效組織代碼。

本文討論了在PHP中管理文件上傳大小的管理,重點是2MB的默認限制以及如何通過修改PHP.INI設置來增加它。

本文討論了PHP 7.1中引入的PHP中的無效類型,允許變量或參數為指定類型或NULL。它突出顯示了諸如提高可讀性,類型安全性和明確意圖的好處,並解釋瞭如何聲明

本文討論了unset()和unlink()功能在編程中的差異,重點關注其目的和用例。 unset()從內存中刪除變量,而unlink()從文件系統中刪除文件。兩者都對效率至關重要


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具