PHP 中获取文件名及路径

1.basename("/mnt/img/image01.jpg")函数:得到文件名;输出结果为:image01.jpg.

使用 basename($uriString) 我们可以得到一个包含扩展名的文件名;

如果不需要扩展名,也可以使用 basename($uriString, $extString) 过滤扩展名,仅仅返回文件名。

2.echo __FILE__;得到当前请求文件的完整路径,输出格式如:/mnt/hgfs/ictsapce/test/index.php

3.dirname() 函数返回路径中的目录部分。如:

echo dirname("/testweb/home.php");

输出:/testweb

Read More

php cache类代码(php数据缓存类)

php的执行效率很高,速度很快,但是连接数据库、查询数据库等还是比较耗时的。
如果访问量大的话会给数据库造成很大的负担,所以对于变化不经常的内容要做好php 数据cache(缓存)是十分必要的,我做了一个简单的php“文件缓存”的类,希望对大家有所帮助。

思路是这样的:

对于一般的变量,把该变量变成php语言的格式,写到文件中,用时只要include这个文件就相当于加载了cache了;
对于array型的变量,把array转化为php语言定义array的字符串,写到文件中,用时也只要include就相当于加载了cache了;
缓存cache时间上的控制,通过获取缓存文件的创建时间和现在的时间进行对比,如果没有到更新时间,直接读取缓存,如果到了更新时间,查询数据库,返回数据,再更新缓存。(尚未实现)

Read More

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