tp5基于workerman实现browsersync开发利器
作者寄语:
基于nodejs的浏览器自动刷新,现已有http://www.browsersync.cn/,该工具实现了代码修改浏览器自动刷新功能。据说能提高约30%的开发效率,但是必须得安装nodejs,node比较耗资源,而且对于php开发人员来说维护起来比较麻烦。故开发php版本的同步刷新工具。基于workerman+tp5,算是php开发者的一个福音吧。

github地址:https://github.com/skj198568/browser_sync
注意:目前Linux、Mac系统完美使用。win系统wokerman可能有问题,也可进行试用,如有问题及时沟通。
1.安装workerman
composer require workerman/workerman2.下载附件,覆盖您的项目目录3.具体用法:
a.项目根目录执行
php think......
Available commands:
browser_sync 监听服务器文件,当文件修改时,自动同步刷新浏览器
build Build Application Dirs
clear Clear runtime file
help Displays help for a command
list Lists commands
model_create 依据数据库表自动创建Model文件
task_run 执行定时任务,请配置:application/console/task_run.ini
......b.使用帮助php think browser_sync --helpUsage:
browser_sync [options]
Options:
-f, --file_types=FILE_TYPES 监听变化的文件后缀名,分号分割,例如:html;js;css;php [default: "html;js;css;php"]
-d, --dirs=DIRS 监听web根目录下变化的文件夹,分号分割,例如:application;public [default: "application;public"]
-p, --port=PORT socket监听的端口,注意防火墙的设置 [default: "8000"]
-c, --command=COMMAND start/启动,start-d/启动(守护进程),status/状态, restart/重启,reload/平滑重启,stop/停止 [default: "start"]
-h, --help Display this help message
-V, --version Display this console version
-q, --quiet Do not output any message
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debugc.默认方式使用php think browser_syncd.后台执行php think browser_sync -c start-de.仅仅监听php文件php think browser_sync -f phpf.使用6000端口php think browser_sync -p 6000g.浏览器访问该网站,会在网页底部拼接相关代码<script type="text/javascript">
var ws = new WebSocket('ws://yourdomain:8000');
ws.onclose = function(){
window.location.reload();
};
</script>f.修改任意被监听的代码,这时浏览器会自动刷新。如有问题,请发邮件:

