Session variables grow huge for no reason

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Session variables grow huge for no reason

Post by Tubbietoeter »

Hi there,


I hope you guys can help me.
I got a very slow database here so I decided to save the results of the select statements into a session variable for futher use. Right now the select returns 31000 rows, this is 5 MB in a flat file. I wanted to save the result array into a session variable.

Now, thats my problem; at the end of the script when PHP writes the session, it fails. I get a message that my allowed memory size is exhaustet.
The memory limit is 50 MB so I really don't know what PHP is saving there if I want to save 5 MB in an array.

The array has 2 dimensions, 10x31000 ($array['COLUMN'][index]).


Please help me ... this is driving me nuts!! :roll:


Thanks,


Stefanie
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

take a look at http://www.php.net/manual/en/configurat ... rce-limits
Are you sure your database is that slow to justify writing so many records to a flat file?
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

Well the database needs more than a minute to return the results of that select. A colleague is working on that, he tries to speed up the database. Unfortunately the workstation with the database is ancient so I don't count on him doing any miracles.


Er, I suppose I have to be root in order to set the memory limit higher? I'd need to tell my admin to do this for me then.



Anyways, I don't want to save the results in a flat file but in a session variable. I just don't know why that damn variable gets so huge ... :roll:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

sessions are stored in flat files by default and the file is read at session_start() (for each invokation of the script for the client with this sessionId) and written when your script ends...

and just a small calculation: By default you have 8mb, that is 8*1024*1024=8388608 bytes
8388608 / (31000*10) = 27,..
Even if(!) php wouldn't need any other memory... ;)
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

So where does that error message come from?
I don't get it ...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Even if(!) php wouldn't need any other memory...
That is not the case and even 27 bytes per entry is ...hmmm... tight?

There's no chance to prevent 31k recordsets (to be stored)?
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

No not really. The results are shown in a table with x pages, the user can flip through the pages. if I would select only the results i needed for the current page the user would again have to wait a minute when he goes to the next screen. Also the entries must be sorted on users click.
if I do that live on the DB (as I originally intendes) things just get too slow.

I'll try materialyzed views today maybe this helps.


Thanks for your help!


Steff
Post Reply