Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$_SESSION verses a database call 1

Status
Not open for further replies.

Zilflic

Programmer
Feb 23, 2005
17
US
When my company initially designed our project we expected it to be a small addition to another much larger system. We figured there would be about 4 screens that would need the same information and we were planning to use $_SESSION variable.

After we got started the president of the company received an enormous amount of positive feedback from our test customers and decided to expand the project to cover the entire scope of the suite we offer. This is a huge step for the company since all of its programs are text-based. The application layer of our program is written in a proprietary language that at times takes a while (sometimes up to 30 seconds) to do large computations. We will be running our software only on company intranets, but I am trying to keep the site as optimized as possible due to the latency that frequently happens from the application layer.

My main question right now deals with $_SESSION and its contents. Would it be faster to use database calls on each of the approx. 4 pages or on the first page and set session variables? So far in the one section we have designed we are looking at 30 session variables every variable except for 1 will be 30 characters or less and one has a max character value of 200. We also use $_GLOBAL variables to store the text on the pages for the current language the user has in preferences.

If $_SESSION is the right way to go we were planning to set it equal to array() when the leave a certain section so that there would not be much to carry over and so we can set that sections variables.

Any insight as to which way to go would be great.

Thanks,

Ann
 
We are planning for a PostgreSQL database. What we wrote earlier didn't use a database for the GUI display so I am not sure about connectivity. Right now we are using WAMP to view the code but will be up on an apache server (hopefully) by the end of the week.
 
In terms of pure performance, you're probably better going with storing everything in session variables. Issuing one session_start() and letting compiled code instantiate the variables in the script will likely be faster than running a set of interpreted database commands to fetch the data. Just make sure that your web server's hard drive has sufficient free space for your user load.

Whether it would be more convenient for your code to store a minimum amount of data in the session and fetch everything from the server is dependent on your code and what you will do with it. In the last e-commerce app I wrote, I stored everthing in sessions, but stored the session serializations on the database server (see faq434-2037). It was more convenient to let custom destroy and garbage-collection handlers move items from abandoned shopping-carts back into inventory. The database server, however, was directly connected to the web server via a crossover cable to maximize network performance.

In general, I'd probably just advise you to stick with storing everything in session variables.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thank you for your fast response and the FAQ. I've printed it to discuss this in our meeting tomorrow.

Do you know of any sites that talk about design considerations using php functions especially about the tradeoff costs (time, space,...)? Or is this something I have to wait for while I gain more experience in PHP? The php.net site is a good reference for the code, but not much more.

Thanks!

-Ann
 
It is really the kind of thing that you will have to have more experience in PHP to answer. You're trying to find the solution to a multivariant function, and without understanding your specific program environment and application functionality, a lot of the variables will be unknown.

If you have questions, I and others in this forum will be, I'm sure, more than happy to answer them.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top