php文件缓存数据

最近在做微信的摇一摇跑马活动,实现原理是用户摇动手机,通过ajax往数据库写入数据(小马跑的步数),然后PC端用过ajax每一秒钟从数据库中调取一次数据(小马跑的步数),然后显示在PC屏幕上,这样就会非常频繁的读写数据库,而且小马跑步的数据只要活动结束即可清除,完全没有存入数据库的必要。

这个功能由于不能够做成静态化,那么就只能够动态,用动态的时候会对数据库和服务器压力带来很大的考验。

所以就只能用到缓存数据的方式了。

Read More

mysqldumpslow使用说明总结

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
mysqldumpslow --help
Usage: mysqldumpslow [ OPTS... ] [ LOGS... ]

Parse and summarize the MySQL slow query log. Options are

--verbose verbose
--debug debug
--help write this text to standard output

-v verbose 输出详细信息
-d debug
-s ORDER what to sort by (al, at, ar, c, l, r, t), 'at' is default
al: average lock time
ar: average rows sent
at: average query time
c: count
l: lock time
r: rows sent
t: query time
-r reverse the sort order (largest last instead of first)
-t NUM just show the top n queries
-a don't abstract all numbers to N and strings to 'S'
-n NUM abstract numbers with at least n digits within names
-g PATTERN grep: only consider stmts that include this string
-h HOSTNAME hostname of db server for *-slow.log filename (can be wildcard),
default is '*', i.e. match all
-i NAME name of server instance (if using mysql.server startup script)
-l don't subtract lock time from total time

Read More

查看mysql数据库连接数、并发数相关信息

1
2
3
4
5
6
7
8
9
mysql> show status like 'Threads%';
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| Threads_cached | 58 |
| Threads_connected | 57 | ###这个数值指的是打开的连接数
| Threads_created | 3676 |
| Threads_running | 4 | ###这个数值指的是激活的连接数,这个数值一般远低于connected数值
+----------------------------+--------+

Threads_connected 跟show processlist结果相同,表示当前连接数。准确的来说,Threads_running是代表当前并发数

Read More

PHP的时间函数strtotime

时间加减

1
2
3
4
<?php  
//获取本地 提取年份+1
$date=date("Y-m-d",mktime(0,0,0,date("m") ,date("d"),date("Y")+1));
?>

如果要获取数据库中的时间应该如何处理呢?在PHP文档中找到了一个很好的函数strtotime,可以对时间进行加减:
int strtotime ( string time [, int now] )
返回类型 int

Read More