PHP 包含和加载时间
如果我将 PHP 添加到页面中。
include('example.php')- It then has to load that file which would / could slow down load time correct? Right now I am making unnecessary redirects back to the a login page if the logins are wrong via javascript snippet that is inside my login.php page (which does all the login checking against the database). So in the address bar it shows "admin.php > login.php > admin.php" , but I don't ever want to show what file it is going to in order to test the logins, but I also do not want to include this inside admin.php because I'm afraid it might affect load time.
如果您理解我的问题,那么建议将会有所帮助。
If I add PHP includes to a page.
include('example.php')
- It then has to load that file which would / could slow down load time correct? Right now I am making unnecessary redirects back to the a login page if the logins are wrong via javascript snippet that is inside my login.php page (which does all the login checking against the database). So in the address bar it shows "admin.php > login.php > admin.php" , but I don't ever want to show what file it is going to in order to test the logins, but I also do not want to include this inside admin.php because I'm afraid it might affect load time.
If you understand my question then suggestions would be helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就服务器端的可读性和可维护性而言,做您认为最好的事情。然后,如果您遇到性能问题,请通过测量(而不是猜测)找到问题的根源,并尝试优化。
你过早地进行优化,这是万恶之源。与执行 HTTP 请求/响应所需的时间相比,包括一些额外的 PHP 行肯定可以忽略不计。
Do what you feel is best in terms of readability and maintainability at server-side. Then, if you have a performance problem, find where it comes from by measuring (and not guessing), and try to optimize.
You're optimizing prematurely, and this is the root of all evil. Compared to the time it takes to a HTTP request/response to execute, including some additional lines of PHP is very certainly negligible.
新的 HTTP 请求(重定向)总是比包含请求对性能造成更大的影响,因此如果您只关心性能,则没有理由使用重定向(尤其是 Javascript 请求)。因此,如果我理解您的意思,我想建议您只包含该文件。
New HTTP requests (redirects) are always a bigger performance hit than includes, so there's no reason to use redirects (especially Javascript ones) if you're only concerned about the performance. So if I understand you I'd like to suggest that you just include the file.