学会知道运算符优先级

运算符优先级
结合方向 运算符 附加信息
非结合 clone new clonenew
[ array()
非结合 ++ – 递增/递减运算符
非结合 ~ – (int) (float) (string) (array) (object) (bool) @ 类型
非结合 instanceof 类型
右结合 ! 逻辑操作符
* / % 算术运算符
+ – . 算术运算符字符串运算符
<< >> 位运算符
非结合 < <= > >= <> 比较运算符
非结合 == != === !== 比较运算符
& 位运算符引用
^ 位运算符
| 位运算符
&& 逻辑运算符
|| 逻辑运算符
? : 三元运算符
= += -= *= /= .= %= &= |= ^= <<= >>= 赋值运算符
and 逻辑运算符
xor 逻辑运算符
or 逻辑运算符
, 多处用到
发表在 php | 留下评论

监听服务端脚本

#!/bin/bash
day=`date -d “now” +%Y%m%d`
logdir=/home/users/sss/local/nginx/monitor/log/${day}
if [ ! -d $logdir ];then
mkdir -p $logdir
wait
fi;
netstat -tnpl |grep ‘:9999′
single=`echo $?`
if [ -n $single ] && [ $single -eq 1 ];then
now_time=`date -d “now” +%H:%M:%S`
echo ‘['${now_time}']try to restart…’ >> ${logdir}/work.log
/home/users/sss/local/php/bin/php-cgi -b 9999 -c /home/users/sss/local/php/etc/php.ini >> ${logdir}/work.log 2>>$logdir/wf.log 1>/dev/null &
exit
fi

发表在 bash | 留下评论

php中特殊的变量$argc/$argv

cli下经常会给脚本传递参数,php中用来接收参数的变量

function main($argc, $argv) {
printf(“params error, argc=%s, argv=%s”, $argc, print_r($argv, true));
}

main($argc,$argv);

==============================

output:

$ php test.php 2 `date +”%Y-%m-%d” -d “-1 days”`

params error, argc=3, argv=Array
(
[0] => test.php
[1] => 2
[2] => 2016-02-25
)

 

发表在 php | 留下评论

c10k问题

简单说就是网站同时有一万人在线,网站出现问题。

以下是参考文档

http://rango.swoole.com/archives/381

http://blog.acoak.com/article/c10k-problem-introduction

 

发表在 互联网 | 留下评论

Apache2.4 更新内容

配置不一样了

http://httpd.apache.org/docs/2.4/upgrading.html

发表在 apache | 留下评论

awk 打印倒数第n列字段

awk ' { print $(NF-1) }' file
发表在 awk | 留下评论

计数运算

$ export i=0
$ for F in `wallet_stat_db -N -e “select count(error_code) from t_custom_process_stat where act_date=’2016-01-17′ and app_code=’nuomi’ and process_id=1 and product_id=4 group by error_code; “`; do if [ $F -gt 1 ]; then i=$(($i+$F)); fi; done;
$ echo $i

发表在 bash | 留下评论

删除一些特殊字符命名的文件

有一次我由于误操作创建了一个有特殊符号的文件

drwxrwxr-x 6 v_haowenzhi v_haowenzhi 4096 Jan 15 16:45 svn
drwxr-xr-x 5 v_haowenzhi v_haowenzhi 4096 Jul 14 2015 svn_base
drwxrwxr-x 2 v_haowenzhi v_haowenzhi 4096 Mar 19 2015 temp
drwxrwxr-x 6 v_haowenzhi v_haowenzhi 4096 Dec 19 16:07 tmp
-rw-r–r– 1 v_haowenzhi v_haowenzhi 11153 Jan 18 11:26 tomer_id = ’3′) AND (wallet_branch_order_type = 1) AND (wallet_branch_order_value != ”) AND (wallet_branch
-rwxr-xr-x 1 v_haowenzhi v_haowenzhi 9059 Jun 9 2015 upload.py
drwxrwxr-x 3 v_haowenzhi v_haowenzhi 4096 Oct 10 13:15 work
drwxrwxr-x 5 v_haowenzhi v_haowenzhi 4096 Jul 28 15:26 www

 

这明显就是个sql字符串,这时可以用通配符删除

rm *wallet_branch_order_type*

发表在 bash | 留下评论

逐行读取文件中sql语句导入到mysql

cat ~/odp/app/etl/script/log/custom.log.20160117.sql |while read LINE; do wallet_stat_db -e “$LINE”; echo $LINE; wait;  done

 

文件格式大概如下:

INSERT wallet_stat_db.t_custom_process_stat SET Walk_track=’P1101_EU1103V1001_P1103′, Process_id=’1′, Page_step=’1′, Order_type=’1′, Product_id=’4′, Customer_id=’27′, loss_type=’2′, app_code=’bdread’, Event_code=’EU1130′, Event_step=’1′, Error_code=’15500′, Error_cate=’981′, Act_date=’2016-01-17′, Total_cnt=1
INSERT wallet_stat_db.t_custom_process_stat SET Walk_track=’P1101_EU1103V1001_P1103′, Process_id=’1′, Page_step=’1′, Order_type=’1′, Product_id=’4′, Customer_id=’27′, loss_type=’2′, app_code=’bdread’, Event_code=’EU1130′, Event_step=’1′, Error_code=’41004′, Error_cate=’624′, Act_date=’2016-01-17′, Total_cnt=1

发表在 bash | 留下评论

seq用法

 

Usage: seq [OPTION]… LAST
or: seq [OPTION]… FIRST LAST
or: seq [OPTION]… FIRST INCREMENT LAST
Print numbers from FIRST to LAST, in steps of INCREMENT.

-f, –format=FORMAT use printf style floating-point FORMAT (default: %g)
-s, –separator=STRING use STRING to separate numbers (default: \n)
-w, –equal-width equalize width by padding with leading zeroes
–help display this help and exit
–version output version information and exit

If FIRST or INCREMENT is omitted, it defaults to 1. That is, an
omitted INCREMENT defaults to 1 even when LAST is smaller than FIRST.
FIRST, INCREMENT, and LAST are interpreted as floating point values.
INCREMENT is usually positive if FIRST is smaller than LAST, and
INCREMENT is usually negative if FIRST is greater than LAST.
When given, the FORMAT argument must contain exactly one of
the printf-style, floating point output formats %e, %f, %g

 

 

demo1#seq -f “%3g+” 0 9

0+
1+
2+
3+
4+
5+
6+
7+
8+
9+

格式化并将前面填充三个空格

demo2#seq -f “%3g” -s, 0 9

0,  1,  2,  3,  4,  5,  6,  7,  8,  9

分割符,默认为\n

 

demo3#seq -s, -w 0 10

00,01,02,03,04,05,06,07,08,09,10

填充前置0和最大值一样的位宽

 

小提示:-w 和 -f不能一起使用,想想其实也是

发表在 bash | 留下评论