Forum Moderators: coopster

Message Too Old, No Replies

Custom Variables for all users

Variable assignment to reduce db access

         

streamline

8:14 pm on Mar 14, 2011 (gmt 0)

10+ Year Member



The answer to my question may be out there but I am unable t ascertain the answer due to perhaps the ways it is asked or answered, so I will try myself and I hope a few of you could comment.
I would like to cache my reference(non changing) data that exists in my mysql database into read only memory on the web server (so others cannot change it) and access this data across any session any page and any user, so as the server starts up, it runs a mysql script from ? a php script ? or what ever it takes for my php pages to be able to access. I do not want to have a web page that my users can access to have to run the mysql queury to find the value for a variable that is needed in the page. I just want to run the sql 1 time by the system and have all my users be able to access it. There has to be a definitive(best practice) way to accomplish this and I hope someone here can provide some guidance. I understand that a superglobal may accomplish this, but can I define a superglobal array to use. Simply wanting to reduce the number of db reads for data that does not change. Thanks alot for any guidance you can provide

omoutop

8:08 am on Mar 15, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just a thought, if i understand you correctly.
How about setting up a crontab job to be executed once per day?
The cron could create a txt file. Your php user pages can read/access that file for basic settings (paths/css/etc)

brotherhood of LAN

8:35 am on Mar 15, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to the forums streamline,

omoutop's crontab and text file suggestion would work well, you can alter the permissions of the file to read only and have it above your web root or blocked via .htaccess

If you're not on a shared server (or you are but have the ability to do these):

- PHP's shared memory functions [php.net] might be of use. You would load your data into a space in memory (perhaps by crontab) and users/scripts could access it. I say 'not on a shared server' as they typically have memory limits per account.

- Have you tried optimising your database? MyISAM's LOAD INDEX INTO CACHE [dev.mysql.com] makes key lookups on MyISAM tables very quick. The same applies with InnoDB's buffer pool [dev.mysql.com],

number of db reads for data that does not change


If it's not a huge number, the query cache [dev.mysql.com] should take care of it.

These answers really depend on you being able to have some kind of memory available to store data, otherwise storing in a text file would likely get cached by the OS anyway and be super quick.

streamline

1:03 pm on Mar 15, 2011 (gmt 0)

10+ Year Member



Thank you for your replys Omoutop and brotherhood of LAN.
Assuming I am on my own server(virtual/otherwise) OR have access on a shared server.
My goal is to reduce repeatative reads from the database.
Optimization of the database to the best of my/others ability will be performed and is a given, so to speak.
Wanting to minimize the processes taken on by the db wether cached data or not.
I would think there would be methods for php to access memory objects in an optimal manner. I will check out PHP's shared memory functions. Am I to assume based upon your answers to not including Global variables that Global variables is not the approach to take.
Thanks again