Jump to content

PHP Usage? (Cookies?)


Maxis098

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 weeks later...

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.