当你对自己的行为感到懊恼后悔时,唯一的办法就是向前看,下定决心不再犯同样的错误,一定不能让这种低落的情绪霸占大脑的每一分每一秒。
最近多年浪费了太多时间在一些无谓的事情上,实在不该。
唉,说说工作中遇到的一些小问题吧。
1. 查询超过特定大小的文件。
find -type f -size +1M // 查找当前目录下大于1M的文件
2. 磁盘报警,但使用du -lh显示出磁盘仍有大量空间未使用。
一些文件删除时,进程仍在使用,而这些进程并未消亡。可使用如下命令解决此问题。
lsof | grep delete | cut -c 11-15 | xargs kill -9// 查询占用删除文件的进程,截取进程号,然后杀掉进程
3. 修改文件最后更新时间
touch -d " 2 hours ago" filename // filename代表要修改的文件名
4. ThinkPHP _STORAGE_WRITE_ERROR
该问题是由于ThinkPHP项目Runtime目录权限不够,可使用chmod修改权限。
另外一种可能是磁盘已无可用空间。
5. 在使用group by的同时,对某一特定条件的数据条目进行计数,此时不能使用count。如下场景:
查询出每个地区每天订单数,以及今天的订单数量。
select distinct district, count(*) as total_count, sum(if(add_time >= $today_time, 1, 0)) as today_count from order group by district order by today_count desc
// $today_time代表今天的起始时间:$today_time = strtotime('today');
6. 使用load data infile向mysql导入数据最为简便,也最为快速。
load data infile 'D:/data.txt' (ignore) into table goods (character set utf8) fields terminated by '\t' lines teminated by '\r\n' (goods_name, goods_number, ...)
// ignore 表示操作不会因为键值相同而中断,同时最后可指定导入特定的列。
7. mysql在where语句中使用md5进行数据匹配
比如将用户的进行md5()编码后的密码存储于cookie中,进行自动登录。
select * from user where concat('', md5(password), '') = '$password' and user_name = $username;
// 当然这里最好先对传入的数据进行处理,mysql_real_escape_stirng等
8. ThinkPHP中,在Controller中有大量的操作方法,此时你只希望对外开放几个操作,将其他方法修改为private或将其他方法都redirect到可访问操作,这样会显得笨拙以及繁琐。
在initialize中加入如下代码:
$action_name = ACTION_NAME;
$actions_allowed = array('index', 'list', 'about');
if(!in_array($action_name, $actions_allowed ))
$this->redirect('index');
Everybody has ups and downs, the important thing is we have to learn from the disappointments.