473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

$_SESSION[] or $my_array[]

TheServant
1,168 Expert 1GB
Hi guys,
This is my situation. I have 3 sets of data used on every page of my website. Two of these never change, and the reason they are stored in MySQL and recalled into the $_SESSION variable is simply because I want to have one place to update/change them if I ever need to.
What I have been wondering is if I should leave the user specific variables in the session, and define the other variables in another file/array which is called on every page. This makes it easier to manage, less code, and no MySQL, but possibly more arrays.

So right now I have something like (which is only run once):
Expand|Select|Wrap|Line Numbers
  1. /*MySQL get table 1 variables*/
  2. /*Store each fetched variable into $_SESSION*/
  3. /*MySQL get table 2 variables*/
  4. /*Store each fetched variable into $_SESSION*/
  5. /*MySQL get table 3 variables*/
  6. /*Store each fetched variable into $_SESSION*/
  7.  
  8. /*Do stuff with $_SESSION['table1var1'], $_SESSION['table2var3'], $_SESSION['table1var2'], $_SESSION['table3var16']*/
Instead I was thinking:
Expand|Select|Wrap|Line Numbers
  1. /*Do once: MySQL get table 1 variables*/
  2. /*Do once: Store each fetched variable into $_SESSION*/
  3. /*Do every page: include table2.php*/
  4. /*Do every page: include table3.php*/
  5. ...
The included files could be in the form:
Expand|Select|Wrap|Line Numbers
  1. $table2['var1'] = 10;
  2. $table2['var2'] = "John";
  3. $table2['var3'] = 19/10/1986;
  4.  
  5. ***OR***
  6.  
  7. $table2_var1 = 10;
  8. $table2_var2 = "John";
  9. $table2_var3 = 19/10/1986;
I would like to do the 1st option but I wonder if more arrays will be noticeably slower, and if doing this on every page will also slow down the page load? Should I just leave it all in the $_SESSION array? Any advice would be greatly appreciated.
Mar 8 '09 #1
4 1796
devsusen
136 100+
I don't have expart view in this issue, but I prefer to use the 2nd process of using include files. In php version 4.x I had experienced the slow page loading due to storage of lot of variables in the session. From that time onwords I used to store only most req. variables in the session. Other variables I use to put in files (in the form of array) or directly fetch them from database.

I am very much interested to know other experts opinion. I feel this is a interesting isssue to discuss.
Mar 9 '09 #2
TheServant
1,168 Expert 1GB
Thanks for your reply. Just confirming: You saw a visible speed change when you changed from storing everything in the session to other methods?
Mar 9 '09 #3
devsusen
136 100+
@TheServant
Yes, there was good change in speed. Earlier I was putting approx 80 - 90 variables(mixed datatype) in session. I reduced the no. almost to 5-7. Some of the variable I put in the files and some of them I fetched from the database.

I was doing some complex processing and there ware many times I wasn't getting the desired result or I was experiencing the page time out. After I made those changes my scripts were running properly and I got expected results.
Mar 12 '09 #4
TheServant
1,168 Expert 1GB
Thanks for that. I have changed my method to only include constantly variable information in the session (which is still ~50 variables), and all the rest are stored in separate 'variable files' which are called by only the pages that need them. I do not store them in arrays, but rather straight variables.

I have another question which you might have come across: Every page I need to check if there has been an event to notify the user and also replace any outdated data in the session with the new data. This means that every page I am connecting to MySQL and running atleast one query. On some pages I only need maybe 10% of my $_SESSION variables, and I have always wondered if it would be faster to only keep user_id in my $_SESSION, and then call only required values from MySQL every page?

To sum up, is it faster to have a $_SESSION with 50 vars and query 7 values, or $_SESSION with 1 var and average query ~15 values?
Mar 12 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Phil Powell | last post by:
What is the most standardized method of utilizing the CURL functions in PHP (version 4.3.2) to be able to retrieve the contents of a remote URL that happens to be dependent upon $_SESSION for its...
5
by: h | last post by:
I am at my wits end; I can not see A SINGLE THING I'm doing wrong. I've read every fricking session related doc. I've searched every fricking group. NO ONE seems to have had the problem I'm having...
21
by: axlq | last post by:
Someone please tell me if I've discovered a PHP bug. I'm sitting in front of several computers on my home network, behind a NAT firewall/router. I am testing my web site on these different...
12
by: Michael Windsor | last post by:
I've been trying to integrate some PHP pages of my own with some existing code. The details of this are for the support forums for that code (where I have been asking questions), but I wonder if...
2
by: somecrazyguy | last post by:
Take the following code, one would think that there was absolutely no link between $test and $_SESSION. But if you reload the page, guess what... "After=FAILED". Why? Because for some reason,...
4
by: dpinion | last post by:
Greetings, I am trying to do some simple session stuff. However it does not seem as though the session variable is being created for my site. I am running the latest version of PHP and apache that...
4
by: Pseudonyme | last post by:
Dear Sirs and Madams, Receive as information that storing a MYSQL result under $_SESSION was accelerating web page displays processes ? Absolutly needed but impossible to get this working ! I...
2
by: sharonDonnelly | last post by:
Hi Really dumb problem that's got me beat. Can someone help. The prolem: I'm trying to count the number of times an item has been clicked. There are many items. I want to create a session...
3
by: JRough | last post by:
I want to save two variables in a $_SESSION for use in another page: $_SESSION = $mark; $_SESSION = $num; then on the other page I did this to get the value: $mark =$_SESSION; $num =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.