1

I've built an application in PHP that operates on a SaaS multi-tenant architecture. Until now I have a configuration table that has approximately 20 columns - it stores variables such as the language, name, css file location, custom URL and favicon/logo name for each SaaS instance which is then SELECTed as an array in the config file. The config file is included into all scripts and pages.

There has to be a better way to store these variables making them available to the app rather than select 20+ records from a table, set them as variables, using them during the compliation of the PHP script and deliver them to the user. This is adding far more load to my MySQL server than necessary and I dare say it's probably challenging Apache2, too.

What is a good method of achieving this goal? Cookie? Session? XML file?

I'm storing my PHP session ID's in the database and have considered collecting the variables when a user logs in and adding them to a plain text or XML file with the same session ID in the file name. I can then have a cronjob that runs garbage collection on the config files (look for file name X in database and if not found unlink X, in its simplest form).

At the moment, I'm thinking either a cookie or creating a file with the session id containing the values. Either option will remove the need to collect these database values and set them as variables on every page load.

Thoughts and suggestions?

Thank you, Michael

Arbiter
  • 486
  • 1
  • 8
  • 21
  • "far more load" ? You should clock the actual cost of pulling these variables from the database. It is almost certainly negligible (to be compared to the total execution time of the script). These variables are likely to be always served from the MySQL query cache anyways (I assume they are not changed frequently). – RandomSeed Aug 07 '14 at 14:15
  • And there I am forgetting about the query cache... heh. It would still be nice to hear from others as PHP is still having to go to the MySQL server to get the values each time from the cache. It would be nice to think that once collected it would be more efficient to store them on the apache server than have to send a query to the database server and bring back the results? – Arbiter Aug 07 '14 at 14:20
  • But to actually answer your question: [APC](http://php.net/manual/en/function.apc-store.php), [Memcache](http://memcached.org/), [Redis](http://redis.io/), and many more. But certainly not cookies, which are highly insecure (clients have full access to the cookie contents). – RandomSeed Aug 07 '14 at 14:23
  • Thanks @RandomSeed - what about an array in a session? :3 I'll rad these sites now. – Arbiter Aug 07 '14 at 14:24
  • Sessions are an option, but I reckon it would be difficult to manage changes dynamically: session variables live until the end of the session (well, by definition ;), how would you apply a configuration change to existing sessions? It also sounds illogical, this is not *session* data. – RandomSeed Aug 07 '14 at 14:30
  • I'm seeing memcache and memcached - different? Same thing? One better than the other? Reading their doc's now – Arbiter Aug 07 '14 at 14:49
  • http://stackoverflow.com/q/1442411/1446005 – RandomSeed Aug 07 '14 at 14:55

0 Answers0