mac 下 rsync + fswatch 自动同步

mac 下没有inotifywait,替代品是swatch,brewhome安装。

#!/usr/bin/env bash
dirPrefixPhp='/Users/Ares/Documents/Work/php'
excludeCommon="app/cache/* app/logs/* app/runtime/*"
projectArr[0]=$dirPrefixPhp'/ald/xxx1'
projectArr[1]=$dirPrefixPhp'/ald/xxx2'
projectArr[2]=$dirPrefixPhp'/ald/xxx3'
rsyncArr[0]='-e "ssh -p222" root@ip0:/srv/www/xxx1'
rsyncArr[1]='-e "ssh -p222" root@ip1:/srv/www/xxx2'
rsyncArr[2]='root@ip2:/srv/www/xxx2'
#wild card,seperated by space
exclude[0]='public/_captcha/*'
exclude[2]='system/caches/*'
watchArgs=$*
if [ -z "$watchArgs" ];then
	watchArgs='.'
fi
fswatch --exclude=\\.git --exclude=\\.svn --exclude=\\.settings --exclude=\\.project --exclude=\\.buildpath $watchArgs|while read v;do
	if [ ! -e $v ];then
		continue
	fi
	for k1 in ${!projectArr[*]};do
		dirPrefix=${projectArr[$k1]}
		if [ "${v:0:${#dirPrefix}}" = "$dirPrefix" ];then
			path=${v#$dirPrefix}
			excludeK1=($excludeCommon' '${exclude[$k1]})
			if [ -n "$excludeK1" ];then
				for v2 in ${excludeK1[*]};do
					if [[ "${path:1}" == $v2 ]];then
						break 2
					fi
				done
			fi
			rsync='rsync -avz -R --chown apache:apache'
			rsync="cd ${projectArr[$k1]} && "$rsync' .'$path' '${rsyncArr[$k1]}' --no-p --no-t'
			dst=${rsyncArr[$k1]#*@}
			#dst=${dst%:*}
			#echo -n '['`date +%H:%M:%S`'] '${projectArr[$k1]##*/}$path' => '$dst
			echo -n '['`date +%H:%M:%S`']' $dst$path
			time=$( (time eval $rsync > /dev/null) 2>&1|head -n2|tail -n1|cut -f2)
			if [ 0 -eq $? ];then
				echo -ne " \033[32mOK\033[0m"
			else
				echo -ne " \033[31mFAILED\033[0m"
			fi
			echo '('${time:2}')'
		fi
	done
done

 

Mac ZendStudio 字体过小问题解决

Mac下ZendStudio有个问题,项目列表字体巨小无比,大显示器上没法看。解决办法如下:

Finder->应用程序 找到 Zend Studio点右键,显示包内容,进入Contents->Eclipse,编辑ZendStudio.ini,找到

-Dorg.eclipse.swt.internal.carbon.smallFonts

这一行,最前面加#注释掉,重启Zend Studio即可。

nginx 实现带burst的并发连接数控制

先安装openresty,直接去官网下载https://openresty.org

lua插件https://github.com/openresty/lua-resty-limit-traffic/blob/master/lib/resty/limit/conn.md

conf/conf.d/xxx.com.conf

lua_shared_dict limit_conn_store 8m;
server {
    listen 8080;
    server_name xxx.com;
    root /srv/www/xxx/public;
    include php;
}

conf/php

if (!-e $request_filename) {
    rewrite  ^/(.*)$  /index.php/$1 last;
}
location ~* \.php($|/) {
        access_by_lua_file lua/conn_access.lua;
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        fastcgi_param SERVER_NAME       $server_name;
        fastcgi_param PATH_INFO         $fastcgi_script_name;
        log_by_lua_file lua/conn_log.lua;
}

继续阅读

swoole http server systemd 脚本

[Unit]
Description=Swoole Http Server
After=network.target
After=syslog.target

[Service]
Type=forking
PIDFile=/run/swoole_xxx.pid
ExecStart=/usr/bin/php /srv/www/xxx/server.php
ExecStop=/bin/kill $MAINPID
ExecReload=/bin/kill -USR1 $MAINPID
Restart=always

[Install]
WantedBy=multi-user.target graphical.target

参考:https://wiki.swoole.com/wiki/page/699.html