如何掌握性能优化、Web安全、Linux常用命令
本篇内容介绍了“如何掌握性能优化、Web安全、Linux常用命令”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

创新互联建站-专业网站定制、快速模板网站建设、高性价比恩平网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式恩平网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖恩平地区。费用合理售后完善,10年实体公司更值得信赖。
1.性能优化
1.1 原则
①多使用内存、缓存、或其他方法
②减少CPU计算量,减少网络加载耗时
③适应于所有编程的性能优化——空间换时间
1.2 让加载更快
1.3 让渲染更快
1.4 缓存
1.5 SSR
1.6 懒加载
1.7 防抖及其封装
「防抖」
「应用场景」(帮助你更好理解防抖)
①登录、发短信等按钮避免用户点击太快,以至于发送了多次请求,需要防抖
②调整浏览器窗口大小时,resize次数过于频繁,造成计算过多,此时需要一次到位
③文本编辑器实时保存,当无任何更改操作1秒后进行保存
④用户输入结束或暂停时,才会触发change事件,类似搜索框中输入信息停下来1秒后才会出现可能要搜索的内容
「手写防抖封装」
function debounce ( fn , delay = 500 ) { let timer = null // timer在闭包中,不对外暴露,以免不小心获取进行修改造成错误 return function () { if( timer ){ clearTimeout( timer ) } // 清空定时器 timer = setTimeout( () => { fn.apply( this , arguments ) timer = null } , delay ) } }1.8 节流及其封装
「节流」
「应用场景」(帮助你更好理解防抖)
「手写节流封装」
function throttle ( fn , delay = 100 ) { let timer = null return function (){ if( timer ){ return } timer = setTimeout( () => { fn.apply( this , arguments ) // 这里不能用fn(),会报错,无法获得事件源对象event timer = null } , delay ) // delay设置的时间内重复执行的定时任务会被清空 } }1.9 为什么防抖的是clearTimeout(timer),而节流的是return?
防抖是触发间隔大于time触发,所以每次在小于间隔time要清除上个定时器,而节流是不管time内触发多少次,只会每隔time时间触发一次,所以用return
假设time=100ms,一个人每50ms输入一个字符,连续10次,即500ms后防抖只会触发一次,而节流会触发5次。为什么呢?因为防抖的意思即输入完停止100ms后触发事件,而节流是控制100ms触发一次事件,所以防抖触发一次,节流会触发五次。(结合「体会防抖重在清零,节流重在加锁」这两句话)
2.Web安全
2.1 XSS攻击
「XSS跨站请求攻击」
以下都是可能发生的XSS注入攻击
在 HTML 中内嵌的文本中,恶意内容以 script 标签形成注入
在内联的 JavaScript中,拼接的数据突破了原本的限制(字符串,变量,方法名等)
在标签属性中,恶意内容包含引号,从而突破属性值的限制,注入其他属性或者标签
在标签的 href、src 等属性中,包含 javascript: 等可执行代码
在 onload、onerror、onclick 等事件中,注入不受控制代码
在 style 属性和标签中,包含类似 background-image:url("javascript:..."); 的代码(新版本浏览器已经可以防范)
在 style 属性和标签中,包含类似 expression(...) 的 CSS 表达式代码(新版本浏览器已经可以防范)
「XSS攻击场景」
一个博客网站,我发表一篇博客,其中嵌入
基本
文件
流程
错误
SQL
调试
- 请求信息 : 2026-06-05 23:38:08 HTTP/1.1 GET : /article/jhoejo.html
- 运行时间 : 2.8580s ( Load:0.0067s Init:2.2480s Exec:0.5941s Template:0.0091s )
- 吞吐率 : 0.35req/s
- 内存开销 : 2,247.61 kb
- 查询信息 : 12 queries 5 writes
- 文件加载 : 36
- 缓存信息 : 0 gets 0 writes
- 配置加载 : 130
- 会话信息 : SESSION_ID=ffvk1fj1c0an2sl0mme0nhotn6
- /www/wwwroot/tsicrk.com/index.php ( 1.09 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/ThinkPHP.php ( 4.61 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Think.class.php ( 12.26 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Storage.class.php ( 1.37 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Storage/Driver/File.class.php ( 3.52 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Mode/common.php ( 2.82 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Common/functions.php ( 53.56 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Hook.class.php ( 4.01 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/App.class.php ( 13.49 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Dispatcher.class.php ( 14.79 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Route.class.php ( 13.36 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Controller.class.php ( 11.23 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/View.class.php ( 7.59 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/BuildLiteBehavior.class.php ( 3.68 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php ( 3.88 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ContentReplaceBehavior.class.php ( 1.91 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Conf/convention.php ( 11.15 KB )
- /www/wwwroot/tsicrk.com/App/Common/Conf/config.php ( 2.14 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Lang/zh-cn.php ( 2.55 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Conf/debug.php ( 1.49 KB )
- /www/wwwroot/tsicrk.com/App/Home/Conf/config.php ( 0.31 KB )
- /www/wwwroot/tsicrk.com/App/Home/Common/function.php ( 3.33 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ReadHtmlCacheBehavior.class.php ( 5.62 KB )
- /www/wwwroot/tsicrk.com/App/Home/Controller/ArticleController.class.php ( 6.02 KB )
- /www/wwwroot/tsicrk.com/App/Home/Controller/CommController.class.php ( 1.60 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Model.class.php ( 60.11 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php ( 32.43 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db/Driver/Pdo.class.php ( 16.74 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Cache.class.php ( 3.83 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Cache/Driver/File.class.php ( 5.87 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Template.class.php ( 28.16 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Template/TagLib/Cx.class.php ( 22.40 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Template/TagLib.class.php ( 9.16 KB )
- /www/wwwroot/tsicrk.com/App/Runtime/Cache/Home/7540f392f42b28b481b30614275e4e55.php ( 17.71 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/WriteHtmlCacheBehavior.class.php ( 0.97 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ShowPageTraceBehavior.class.php ( 5.24 KB )
- [ app_init ] --START--
- Run Behavior\BuildLiteBehavior [ RunTime:0.000005s ]
- [ app_init ] --END-- [ RunTime:0.000027s ]
- [ app_begin ] --START--
- Run Behavior\ReadHtmlCacheBehavior [ RunTime:0.000289s ]
- [ app_begin ] --END-- [ RunTime:0.000313s ]
- [ view_parse ] --START--
- [ template_filter ] --START--
- Run Behavior\ContentReplaceBehavior [ RunTime:0.000053s ]
- [ template_filter ] --END-- [ RunTime:0.000086s ]
- Run Behavior\ParseTemplateBehavior [ RunTime:0.006264s ]
- [ view_parse ] --END-- [ RunTime:0.006291s ]
- [ view_filter ] --START--
- Run Behavior\WriteHtmlCacheBehavior [ RunTime:0.000180s ]
- [ view_filter ] --END-- [ RunTime:0.000196s ]
- [ app_end ] --START--
- 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1
[ SQL语句 ] : SELECT `id`,`pid`,`navname` FROM `cx_nav` WHERE ( id= ) LIMIT 1
- 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1
[ SQL语句 ] : SELECT `id`,`navname` FROM `cx_nav` WHERE ( id= ) LIMIT 1
- 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
[ SQL语句 ] : SELECT `id`,`navname` FROM `cx_nav` WHERE ( pid= )
- [8] Undefined index: pid /www/wwwroot/tsicrk.com/App/Home/Controller/ArticleController.class.php 第 47 行.
- [8] Undefined index: db_host /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php 第 120 行.
- [8] Undefined index: db_port /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php 第 121 行.
- [8] Undefined index: db_name /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php 第 122 行.

2.8580s
