简体   繁体   English

缓存php和javascript文件

[英]caching php and javascript file

I have a site that gets around 1000 page views a minute when traffic is high and the page has a js code which stores the browser details of the visitor into mysql using a php file for connecting to db. 我有一个站点,当流量很高时,每分钟大约有1000次页面浏览,并且页面上有一个js代码,该代码使用php文件将访问者的浏览器详细信息存储到mysql中,用于连接到db。 For eg browser.js calls storebrowserdata.php Is there a way for me to cache the php file and js file without affecting my stats data that is stored in the db?? 例如,browser.js调用storebrowserdata.php,是否可以让我缓存php文件和js文件,而又不影响存储在数据库中的统计数据? When the traffic is high during the day the site slows down and cpu utilization also goes up. 当白天的流量很高时,网站速度会变慢,CPU利用率也会上升。

PHP is interpreted. PHP被解释。 If you want to grab each visitor's browser/user agent information on each page load then you kinda need to run that script each time; 如果您想在每次页面加载时获取每个访问者的浏览器/用户代理信息,那么您每次都需要运行该脚本。 you can't cache it. 您无法缓存它。

If this functionality is slowing down your site, either use an alternative solution like Google Analytics, or investigate a NoSQL solution like Mongo DB that offers atomic updates and in general runs faster than MySQL. 如果此功能使您的网站变慢,请使用替代解决方案(例如Google Analytics(分析)),或研究NoSQL解决方案(例如Mongo DB),该解决方案提供原子更新,并且运行速度通常比MySQL快。

you can cache js file as well as php one. 您可以缓存js文件和php文件。
but it will do nothing good for you. 但这对您无济于事。

it's database update that most likely slows down your site. 数据库更新很可能会减慢您的网站速度。

what certain operation consumes most CPU? 某些操作消耗最多的CPU? Did you profile your application? 您是否对您的应用程序进行了简介? Is it the only page using PHP mysql on your site? 这是您网站上唯一使用PHP mysql的页面吗?

If you need to control the flow of process executed, you can use a Queue and control the rate of execution. 如果需要控制执行的流程,则可以使用队列并控制执行速度。

About this system, this is a great open source project: http://www.rabbitmq.com/ 关于此系统,这是一个很棒的开源项目: http : //www.rabbitmq.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM