473,804 Members | 3,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Large array stored in session variable causes server to choke

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
Feb 11 '06 #1
4 3966
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.
js*******@attgl obal.net
=============== ===
Feb 11 '06 #2
On 2006-02-11, MrBiggles <mr**********@y ahoo.com> wrote:
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;
Here I'm limited to something like 3.2K much more than that and the session
data is lost.
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.


maybe you need more ram.

Bye.
Jasen
Feb 12 '06 #3
On 2006-02-12, Jasen Betts <ja***@free.net .nz> wrote:
On 2006-02-11, MrBiggles <mr**********@y ahoo.com> wrote:
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;


Here I'm limited to something like 3.2K much more than that and the session
data is lost.


sorry, no that was a mozilla bug not displaying lines with that many
non-space characters... I've tested sessions upto 2M here - that's about the
limit for this old hardware...
hmm...

I hear (and see in my config file) that PHP gets (by default) 8M of ram
to play with.

60K x 20 is 1200K fields
there's only room for an about 8 bytes per field, four of which are
probably going to be a pointer of some sort there's probably another four
needed for memory allocation control, or a reference counte etc... looks
like you're doomed before you even start.

I did some testing:

$a=array();
for($c=200;$c<6 0000;$c+=200)
{
for($b=$c-200;$b<$c;$b++)
{
$a[$b]=array('1','2', '3','4','5','6' ,'7','8','9','0 ',
'a','b','c','d' ,'e','f','g','h ','i','j');
print('.');
}
print '<br>' .$c; flush();
};
I get about 5500 rows by 20 elements by 1 character each before I exceed
that limit

if you bump the limit up to say 400M you might have some success
(dependant on record sizes).

that means your server wants around 40G of ram to be able to handle 100
simultaneous requessts... (is 100 a reasonable figure??)

ISTM it might be time to re-evaluate the task and either do without the huge
array, or store and process it using some other language (like a databaee
using SQL or a custom app using C, or a combination oof the two)

Bye.
Jasen
Feb 12 '06 #4

"Jasen Betts" <ja***@free.net .nz> wrote in message
news:3f******** *********@clunk er.homenet...
On 2006-02-12, Jasen Betts <ja***@free.net .nz> wrote:
On 2006-02-11, MrBiggles <mr**********@y ahoo.com> wrote:
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;
Here I'm limited to something like 3.2K much more than that and the
session
data is lost.


sorry, no that was a mozilla bug not displaying lines with that many
non-space characters... I've tested sessions upto 2M here - that's about
the
limit for this old hardware...
hmm...

I hear (and see in my config file) that PHP gets (by default) 8M of ram
to play with.

60K x 20 is 1200K fields
there's only room for an about 8 bytes per field, four of which are
probably going to be a pointer of some sort there's probably another four
needed for memory allocation control, or a reference counte etc... looks
like you're doomed before you even start.


struct {
union {
long lval;
double dval;
struct {
char *val;
int len;
} str;
HashTable *ht;
zend_object_val ue obj;
} value;
zend_uint refcount;
zend_uchar type;
zend_uchar is_ref;
} zval;
so the sizeof(double)+ sizeof(unsigned int)+sizeof(uns igned
char)+sizeof(un signed char)
I forgot my C!
I think it's 8+4+1+1.14 bytes to start with, + the sizeof(the HashTable)
when that's all done.
not much detail there. the details about the internal structure of a
hashtable weren't given. sorry. But I suspect this struct is only necessary
once, not repeated every array element, due to the refcount. a refcount is
only needed by the parser/interpreter for certain purposes (like language
"references " & mainly keeping track of pointer counts under the hood).

I did some testing:

$a=array();
for($c=200;$c<6 0000;$c+=200)
{
for($b=$c-200;$b<$c;$b++)
{
$a[$b]=array('1','2', '3','4','5','6' ,'7','8','9','0 ',
'a','b','c','d' ,'e','f','g','h ','i','j');
print('.');
}
print '<br>' .$c; flush();
};
I get about 5500 rows by 20 elements by 1 character each before I exceed
that limit

if you bump the limit up to say 400M you might have some success
(dependant on record sizes).

that means your server wants around 40G of ram to be able to handle 100
simultaneous requessts... (is 100 a reasonable figure??)

ISTM it might be time to re-evaluate the task and either do without the
huge
array, or store and process it using some other language (like a databaee
using SQL or a custom app using C, or a combination oof the two)

Bye.
Jasen

Feb 16 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2021
by: DrewM | last post by:
I'm still thinking about session variables :-) Does anyone know the detail of how session variables are actually stored? The question I'm trying to answer is: Is it more efficient to store and retrieve multiple short strings : a) in multiple small session variables b) concatenated and stored as one large session variable c) inserted into an array and stored in a session variable
11
2548
by: Colin Steadman | last post by:
Hope this makes sense! I'm building an ASP page which allows uses to add items to an invoice via a form, ie: Item No Part No Order No Quanity Units Price VAT ------- ------- -------- ------- ----- ----- --- .... ... ... ... ... ... ... <Add item> <Submit>
3
2998
by: NCZIMM | last post by:
I am trying to create a session array then use the array in a foreach. I get an error saying: "foreach statement cannot operate on variables of type 'object' because 'object' does not contain a definition for 'GetEnumerator', or it is inaccessible" The session is necessary because of postback There are three steps here: 1. populate an array. 2. copy the array to a session array.
5
2203
by: ASP.Confused | last post by:
As you can tell from my previous posts on this issue...I'm really confused :-/ I have a few ASP.NET web applications on my web host's "https" server. Our web host has a single "bin" folder for me to toss my assemblies into. We keep loosing session state every few months. People have told me that my app could be running out of memory, causing the sessions to get reset. Well, if this is the case, then when I go to the page again,...
4
1955
by: T Ralya | last post by:
I am told that ASP.NET controls the session ID and session variables, but that does not fit my symptoms. I am posting here as directed. I'm hoping that someone can at least recommend something to try to isolate the problem. I have a simple application that demonstrates my problem. Page 1, step1: SaveSessionVariableButton will create a string value, show it on screen, save it in a session variable and show the session ID on screen....
1
2148
by: Gregory Hassett | last post by:
Hello, I am calling into a legacy COM server from VB.NET. The method that I am calling expects an array. Here is the example syntax provided by the author of this COM automation object -- this syntax would (allegedly) work in VB6. The object is called RhinoScript: RhinoScript.AddLine Array(0, 0, 0), Array(10, 0, 0) Now, this syntax causes VB.NET to choke at compile-time. I have replaced it with the following (and have tried several
3
2339
by: Brad | last post by:
I am storing an array which contains about a dozen chracter items to a Session variable. Later, I need to use this array so I am doing the following: Dim eventTypes As String() = DirectCast(Session("EventTypes"), String()) If Date.Today <= closeDate Then If eventTypes(cblEntries.SelectedIndex) = "J" Then thisFee = Session("JRFee") Else thisFee = Session("PEFee") Else If eventTypes(cblEntries.SelectedIndex) = "J" Then thisFee =
6
5127
by: divya | last post by:
I have a page name edit.asp which should expire immediately .The user cannot open this page directly he has to provide a password for entering this page.thus when the user enters edit.asp , it has a button EDIT ,which when user clicks directs him to another page (done.asp). Now the problem is that from this page (done.asp) if he clicks on the back button on the toolbar then edit.asp opens.But I don't want it to open It should show page...
1
2831
by: None | last post by:
Hi, I have developed webshop application using asp.net 1.1. I'm using DataGrid in one of the pages of my site. During the page load the DataGrid will be binded by around 7500 products(rows). At the same time i'm storing the DataSet object in the Session Variable for later refinement. I'm using StateServer mode for storeing the session values. But in my server the W3wp.exe is taking 90 - 100 % CPU
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9588
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10589
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.