Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Application of PHP caching Technology

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly talks about "the example application of PHP caching technology". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the example application of PHP cache technology".

We have discussed PHP caching technology in depth before, mainly referring to data caching. Data cache mainly refers to the database query cache. Every time you visit the page, you will first detect whether the corresponding cached data exists. If it does not exist, connect to the database, get the data, and serialize the query results and save them to a file. Later, the same query results will be obtained directly from the cache table or file.

The most widely used example is Discuz's search function, which caches the results ID into a table and searches the cache table the next time you search for the same keyword.

To take a common method, when multiple tables are associated, save the generated array of the contents in the schedule to a field of the main table, and decompose the array when needed. This advantage is to read only one table. The disadvantage is that the two data synchronization will be many more steps, the database is always the bottleneck, using the hard disk for speed is the key point.

Page caching

Every time you visit a page, you will first check whether the corresponding cache page file exists. If it does not exist, connect to the database, get the data, display the page, and generate the cache page file at the same time, so that the page file will work the next time you visit it. (template engines and some cache classes common on the Internet usually have this feature)

Time triggered cache

Check whether the file exists and the timestamp is less than the set expiration time. If the timestamp modified by the file is larger than the current timestamp minus the expiration timestamp, then the cache is used, otherwise the cache is updated.

Content trigger caching

Forces the cache to be updated when data is inserted or updated.

Static cache

The static cache here refers to static, directly generate text files such as HTML or xml, and re-generate when there is an update, which is suitable for pages that do not change much, not to mention.

Memory cache

Memcached is a high-performance, distributed in-memory object cache system, which is used to reduce database load and improve access speed in dynamic applications.

An example of reading the library:

Buffer of PHP

Such as eaccelerator,apc,phpa,xcache and so on.

MySQL caching

This is also non-code-level, the classic database is used in this way, look at the following run time, 0.09xxx and so on.

[client]. Default-character-set=gbk default-storage-engine=MYISAM max_connections=600 max_connect_errors=500 back_log=200 interactive_timeout=7200 query_cache_size=64M... Table_cache=512... Myisam_max_sort_file_size=100G myisam_max_extra_sort_file_size=100G myisam_sort_buffer_size=128M key_buffer_size=1024M read_buffer_size=512M... Thread_concurrency=8

Web caching based on reverse proxy

For example, Nginx,SQUID,mod_PRoxy (mod_proxy and mod_cache above apache2)

An example of NGINX:

# user nobody; worker_processes 4; error_log logs/error.log crit; pid logs/nginx.pid; worker_rlimit_nofile 10240; events {use epoll; worker_connections 51200;} http {include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; tcp_nodelay on; # server pool upstream bspfrontsvr {server 10.10.224 weight=1; server 80 weight=1 } upstream bspimgsvr {server 10.10.10.201:80 weight=1;} upstream bspstylesvr {server 10.10.10.202:80 weight=1;} upstream bsphelpsvr {server 10.10.10.204:80 weight=1;} upstream bspwsisvr {server 10.10.10.203:80 weight=1;} upstream bspadminsvr {server 10.10.10.222:80 weight=1;} upstream bspbuyersvr {server 10.10.10.223:80 weight=1 } upstream bspsellersvr {server 10.10.10.225 weight=1; 80 weight=1;} upstream bsploginsvr {server 10.10.10.220 upstream bsploginsvr 443 weight=1;} upstream bspregistersvr {server 10.10.10.220 weight=1; 80 weight=1;} log_format test_com'$remote_addr-$remote_user [$time_local] "$request"'$status $body_bytes_sent "$http_referer"$http_user_agent"' #-- # img.test.com server {listen 10.10.230 server_name img.test.com; location; server_name img.test.com; location / {proxy_pass http://bspimgsvr; include proxy_setting.conf;} access_log logs/img.log test_com;} # style.test.com server {listen 10.10.230 listen 80 Server_name style.test.com; location / {proxy_pass http://bspstylesvr; include proxy_setting.conf;} access_log logs/style.log test_com;} # help.test.com server {listen 10.10.10.230 server_name style.test.com; location; server_name help.test.com; location / {proxy_pass http://bsphelpsvr; include proxy_setting.conf } access_log logs/help.log test_com;} # admin.test.com server {listen 10.10.10.230 server_name admin.test.com; location; server_name admin.test.com; location / {proxy_pass http://bspadminsvr; include proxy_setting.conf;} access_log logs/admin.log test_com;} # buyer.test.com server {listen 10.10.230 admin.test.com server 80 Server_name buyer.test.com; location / {proxy_pass http://bspbuyersvr; include proxy_setting.conf;} access_log logs/buyer.log test_com;} # seller.test.com server {listen 10.10.10.230 server_name buyer.test.com; location; server_name seller.test.com; location / {proxy_pass http://bspsellersvr; include proxy_setting.conf } access_log logs/seller.log test_com;} # wsi.test.com server {listen 10.10.10.230 server_name wsi.test.com; location; server_name wsi.test.com; location / {proxy_pass http://bspwsisvr; include proxy_setting.conf;} access_log logs/wsi.log test_com;} # www.test.com server {listen 10.10.230 wsi.test.com server 80 Server_name www.test.com * .test.com; location ~ ^ / NginxStatus/ {stub_status on; access_log off;} location / {proxy_pass http://bspfrontsvr; include proxy_setting.conf;} access_log logs/www.log test_com; error_page 500502 503 504 / 50x.htl; location = / 50x.html {root html } # login.test.com server {listen 10.10.10.230 server_name login.test.com; ssl on; ssl_certificate cert.pem; ssl_certificate_key cert.key; ssl_session_timeout 443; server_name login.test.com; ssl on; ssl_certificate cert.pem; ssl_certificate_key cert.key; ssl_session_timeout 5m; ADHV of ssl_protocols SSLv2 SSLv3 TLSv1; ssl_ciphers all: EXPORT56 RC4 of High; ssl_prefer_server_ciphers on of medium Location / {proxy_pass https://bsploginsvr; include proxy_setting.conf;} access_log logs/login.log test_com;} # login.test.com for register server {listen 10.10.10.230 include proxy_setting.conf; 80; server_name login.test.com; location / {proxy_pass http://bspregistersvr; include proxy_setting.conf;} access_log logs/register.log test_com }} proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_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

An example of mod_proxy:

ServerName www.zxsv.com ServerAdmin admin@zxsv.com # reverse proxy setting ProxyPass / http://www.zxsv.com:8080/ ProxyPassReverse / http://www.zxsv.com:8080/ # cache dir root CacheRoot "/ var/www/proxy" # max cache storage CacheSize 50000000 # hour: every 4 hour CacheGcInterval 4 # max page expire time: hour CacheMaxExpire 240 # Expire time = (now-last_modified) * CacheLastModifiedFactor CacheLastModifiedFactor 0.1 # defalt expire tag: hour CacheDefaultExpire force complete after precent Of content retrived: 60-90% CacheForceCompletion 80 CustomLog / usr/local/apache/logs/dev_access_log combined so far I believe that everyone has a deeper understanding of the "example application of PHP cache technology", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report