|
Posted by Jerry Stuckle on 02/12/06 00:03
MrBiggles wrote:
> Here's the sitch:
>
> I read in a csv file with 60000 lines (20 fields per record), and store
> the data to a local array. The file is read in and stored just fine and
> pretty quick.
> Now, if I try to assign that array to a session variable it chokes.
> e.g. create array and load each element with a row from the file (btw,
> each row is an array as well, using fgetcsv()). When local array is
> loaded, I assign to session var as so:
> $_SESSION['mydata'] = localArray;
>
> What happens is the server will sit there and churn for a long time. CPU
> goes to 99% use and memory use explodes on the apache thread. It will
> keep churning a looong time, so long that I had to stop the server to
> make it quit. This happens on my windows server as well as fedoracore4
> server.
>
> I've tried these variations all with the same results:
> - store reference to array in session var (although since it's an array,
> I think it makes no difference). e.g. $_SESSION['mydata'] =& myArray;
>
> - read the file directly into a sesson var, instead of creating a local
> array first. e.g. $_SESSION['mydata'][] = $row; (grabbing one row at a
> time from file)
>
> Same thing always happens.
> Anybody have any insight into storing large arrays as session vars? Is
> it bad practice? Can it be done? What's the scoop?
>
> Any help appreciated!
> Thanks
> B
Let's see... 60K records x 20 fields per record is 1.2M fields. That's
a lot of data. Then multiply by the average size of a field and you
have a lot of MB. I sure wouldn't try to store that much in a session!
Then PHP has to serialize the data to write it to the session file. And
unserialize when it reads the data in. A lot of work for that much data.
Doesn't look like a sound design to me... Maybe use a database instead?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|