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. 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?? When the traffic is high during the day the site slows down and cpu utilization also goes up.
-
why you don't use get_browser function?Hassan Khodadadeh– Hassan Khodadadeh2011-09-11 11:04:19 +00:00Commented Sep 11, 2011 at 11:04
-
How do you want to cache something that by definition has to be run for every visitor? ... As @Death says, storing browser info on server side would be much preferable (if it's just browser info you're storing and not stuff like screen size, which can't be detected using a server side language)Pekka– Pekka2011-09-11 11:08:39 +00:00Commented Sep 11, 2011 at 11:08
-
I store the browser size and run my own query on the data that is got so i cant use google analytics. Also i use the js on multiple sitespeter– peter2011-09-12 03:55:19 +00:00Commented Sep 12, 2011 at 3:55
3 Answers
PHP is interpreted. 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.
Comments
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/