Maxis098 Posted June 29, 2008 Share Posted June 29, 2008 I want to make it on my page so that it will run a PHP query that will gather information from my SQL database, then post it. Which I've already done. However I want to make it so the query will only be run every... say 5 minutes. (The query is on a few pages). Is there anyway I can use PHP to create a cookie or something that while the cookie hasn't expired, won't query the SQL? (I'm new to PHP, but know a handful of basics. Not expecting an entire script or anything either [duh] but just a general concept or something maybe? I appreciate any help you can offer. Quote Link to comment https://forums.phpfreaks.com/topic/112392-php-usage-cookies/ Share on other sites More sharing options...
hitman6003 Posted June 29, 2008 Share Posted June 29, 2008 If you have control over your mysql server, turn on query caching....when the exact same query is issued it will pull the result from the cache and not actually query the database. When the table (or tables) that are selected from are updated in anyway (INSERT, UPDATE, DELETE), it will invalidate the cache and requery... If that isn't an option, then your best bet is to write a text file with the result set. Then use the file's modified time to gauge when to requery. Cookies are user specific...unless that is what you want. Quote Link to comment https://forums.phpfreaks.com/topic/112392-php-usage-cookies/#findComment-577023 Share on other sites More sharing options...
.josh Posted June 29, 2008 Share Posted June 29, 2008 I think if I were to go the text file route I'd consider making a file that runs the query and writes the results into a separate text file. Put that script on a cron job to run every 5 minutes. Then simply include the text file in your pages. Quote Link to comment https://forums.phpfreaks.com/topic/112392-php-usage-cookies/#findComment-577026 Share on other sites More sharing options...
Maxis098 Posted June 29, 2008 Author Share Posted June 29, 2008 Where exactly would I find the query caching option, and is it table specific, or query specific? Quote Link to comment https://forums.phpfreaks.com/topic/112392-php-usage-cookies/#findComment-577031 Share on other sites More sharing options...
hitman6003 Posted June 29, 2008 Share Posted June 29, 2008 It's MySQL instance specific, you set it in the my.(cnf|ini). Most of the time it's already enabled, but there is no memory devoted to it...give it some memory like so... -- the value is set in bytes, so the below is 16 MB SET GLOBAL query_cache_size = (1024 * 1024 * 16); http://dev.mysql.com/doc/refman/5.0/en/query-cache-configuration.html I think you might have to have the SUPER privilege to modify the global query cache...not sure. Quote Link to comment https://forums.phpfreaks.com/topic/112392-php-usage-cookies/#findComment-577033 Share on other sites More sharing options...
Maxis098 Posted July 16, 2008 Author Share Posted July 16, 2008 I would like to revive this topic of mine once more to ask about using a files creation/updated timestamp to trigger a requery? How is this done? If that isn't an option' date=' then your best bet is to write a text file with the result set. Then use the file's modified time to gauge when to requery.[/quote'] Is what I've decided to do, I'm just curious how to make it only query on set times? (Say after the server/computer date is say 5 minutes later than the file date?) --- I think if I were to go the text file route I'd consider making a file that runs the query and writes the results into a separate text file. Put that script on a cron job to run every 5 minutes. Then simply include the text file in your pages. I also just noticed this post again, would it be possible to explain the above, or this slightly more? Quote Link to comment https://forums.phpfreaks.com/topic/112392-php-usage-cookies/#findComment-591338 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.