之前我們曾深入的探討過PHP快取技術,其中主要提到了資料快取。資料快取主要是指資料庫查詢緩存,每次存取頁面的時候,都會先偵測對應的快取資料是否存在,如果不存在,就連接資料庫,得到數據, 並把查詢結...
之前我們曾深入的探討PHP快取技術,其中主要提到了資料快取。資料快取主要是指資料庫查詢緩存,每次造訪頁面的時候,都會先檢測相應的快取資料是否存在,如果不存在,就連接資料庫,得到數據, 並把查詢結果序列化後儲存到文件中,以後同樣的查詢結果就直接從快取表或文件中取得。
用的最廣的例子看Discuz的搜尋功能,把結果ID快取到一個表中,下次搜尋相同關鍵字時先搜尋快取表。
舉個常用的方法,多表關聯的時候,把附表中的內容生成數組保存到主表的一個字段中,需要的時候數組分解一下,這樣的好處是只讀一個表,壞處就是兩個資料同步會多不少步驟,資料庫永遠是瓶頸,用硬碟換速度,是這個的關鍵點。
每次訪問頁面的時候,都會先檢測相應的緩存頁面文件是否存在,如果不存在,就連接數據庫,得到數據,顯示頁面並同時生成緩存頁面文件,這樣下次訪問的時候頁面文件就發揮作用了。 (模板引擎和網路上常見的一些快取類別通常有此功能)
時間觸發快取
檢查檔案是否存在且時間戳小於設定的過期時間,如果檔案修改的時間戳比目前時間減去過時間戳大,那麼就用緩存,否則更新緩存。
內容觸發快取
當插入資料或更新資料時,強制更新快取。
靜態快取
這裡所說的靜態快取是指靜態化,直接產生HTML或xml等文字文件,有更新的時候重生成一次,適合於不太變化的頁面,這就不說了。
記憶體快取
Memcached是高效能的,分散式的記憶體物件快取系統,用於在動態應用中減少資料庫負載,提升存取速度。
$memcache = new Memcache;
$memcache->connect('localhost', 11211) $memcache->connect('localhost', 11211) 11121" = $memcache->getVersion() ;
echo “Server's version: “.$version.”n”;
$tmp_object = new stdClass;
_test.mp_object = new stdClass;
_test. ject->int_attr = 123;
$ memcache->set('key', $tmp_object, false, 10) or die (“Failed to save data at the server”);
echo “Store data in the cache (data will expire in 10 seconds);
$get_result = $memcache->get('key');
echo “Data from the cache:n”;
『var_dump($get_result);
讀庫的範例:
$sql = 'SELECT * FROM users';
$key = md5($sql); //4mmc key)) ) {
// 在memcached 中未取得到快取數據,則使用資料庫查詢取得記錄集
echo “n”.str_pad('Read datas from My.', 60, '_'). n”;
$conn = mysql_connect('localhost', 'test', 'test');
mysql_select_db('test'); hile ($row = mysql_fetch_object($result))
$datas[] = $row;
// 將資料庫中取得的結果集資料儲存到memcached 中,以便在下次存取時使用$com key, $datas);
} else {
echo “n”.str_pad('Read datas from memcached.', 60,} '_').”n”; s);
?>
PHP的緩衝器
例如eaccelerator,apc,phpa,xcache等等。
MySQL快取
這也算非程式碼級的,經典的資料庫就是用的這種方式,看下面的運行時間,0.09xxx之類的。
[client]
……
default-character-set=gbk
『『+〦 ections=600
max_connect_errors=500
back_log=200
interactive_timeout=7200
『 table_cache=512
……
myisam_max_sort_file_size=100G
myisam_max_exmort uffer_size=128M
key_buffer_size= 1024M
read_buffer_size=512M
…
thread_concurrency=88『 如Nginx,SQUID,mod_PRoxy(apache2以上又分為mod_proxy和mod_cache)
NGINX的例子:
#user nobody;
worker_processes 4;
error_log logs/error.log crito; worker_rlimit_nofile 10240;
events {
use epoll;
worker_connections 512000 ;
}
http {
include mime.types;
『
keepalive_timeout 65;
tcp_nodelay on;
# server
server 10.10.10.224:80 weight=1;
server 10.10.10.221:80 weight=1; 㟎
『
server 10.10.10.201:80 weight=1;
}
upstream bspstylesvr {
server 10.10.10.202:80 weight=1;
}
upstream bsphelpsvr.
}
upstream bspwsisvr {
server 10.10.10.203:80 weight =1;
}
upstream bspadminsvr {
server 10.10.10.222:80 weight=1; vr {
server 10.10.10.223:80 weight=1;
}
upstream bspsellers }
upvr bspsellerssvr {
server 10.10.10.225:80 weight=1;
}
upstream bsploginsvr {
}
upstream bspregistersvr {
server 10.10.10.220:80 weight =1;
}
log_format test_com '$remote_addr – $remote_user [$time_local] “$request” '
_$s
靦""
#————— ———————————————–
#img.test.com
server {
listen 10.10.10.230:80; location / {
proxy_pass http://bspimgsvr;
include proxy_setting.conf;
} test>setting.conf;
〜} test>test.test; }
#style.test.com
server {
listen 10.10.10.230:80;
server_name style.test.com;
location / {
proxy_pass http://bspstylescom
}
access_log logs/style.log test_com;
}
#help.test.com
server {
listen 10.10.10.
listen 10.10.10.230:80$com;
location / {
proxy_pass http://bsphelpsvr;
include proxy_setting .conf;
}
access_log logs/help.log test_com;
} 🎀 listen 10.10.10.230:80;
server_name admin.test.com;
location / {
proxy_pass http://bspadminsvr;
include proxy_setting.conf;
include
}
#buyer.test.com
server {
listen 10.10.10.230:80;
server_name buyer.test.com;
location / {
、 .
}
access_log logs/buyer.log test_com;
}
#seller.test.com
伺服器{
聽10.10.10.230:80;
伺服器名稱seller.test.com;
位置/ {
proxy_pass http://bspsellersvr;
佛access_log 日誌/seller.log test_com;
}
#wsi.test.com
伺服器{
聽10.10.10.233); / {
proxy_pass http://bspwsisvr;
包括proxy_setting.conf;
佛}
佛語
凡伺服器{
凡聽10.10.10.230:80;
server_name www.test.com *.test.com;
位置~ ^/NginxStatus/ {
位置~
}
位置/ {
proxy_pass http://bspfrontsvr;
包含proxy_setting.conf;
佛}
505_Ftest> $505050505050 4票化。 2 503 504 / 50x.html;
位置= /50x.html {
凡}
位置= /50x.html {
凡}
凡#login.test.com
凡}
凡#login.test.comcom ;
伺服器名稱login.test.com;
ssl 開啟;
ssl_certificate cert.pem;
:ssl_certificate_key cert.pem;
:ssl_certificate_key cert.key; cols SSLv2 SSLv3 TLSv1;
ssl_ciphers 全部:!ADH :!EXPORT56:RC4+RSA:+高:+中:+低:+SSLv2:+EXP;
ssl_prefer_server_ciphers 開啟;
位置/ {
_c
佛}
佛access_log 日誌/login.log test_com;
凡}
凡#login.test.comcomcomo
凡}
凡#login.test.com7050300600030003700370037名伺服器50. in .test.com;
位置/ {
proxy_pass http://bspregistersvr;
包含proxy_setting.conf;
佛} fxy test
test.
proxy_set_header 主機$host;
proxy_set_header X-真實IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m_xy 85; _timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k ; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k;
mod_proxy 的範例:
irt;
ServerAdmin admin@zxsv.com
#反向代理設定
ProxyPass / http://www.zxsv.com:8080/
ProxyPassReverse / http://www.zxsv. com:8080/
# 快取目錄根根
/Rache
# 最大快取儲存
CacheSize 50000000
# 小時:每4 小時
CacheGcInterval 4
# 小時:每4 小時
:CacheGcInterval 4 Max 707 月
#過期時間= (now – Last_modified) * CacheLastModifiedFactor
CacheLastModifiedFactor 0.1
預設過期標籤:小時
CacheDefaultExpire 1
#ache 檢索內容百分比後強製完成 10% CustomLog /usr/local /apache/logs/dev_access_log 組合

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

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

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


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

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

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

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),