Re: Keeping an Array in Memory

From: Amir Khawaja (amir_at_gorebels.net)
Date: 06/18/04


Date: Thu, 17 Jun 2004 19:39:50 -0700

Andrew wrote:
> I'm afraid I don't know PHP well enough
> to figure this out.
>
> What I would like is to keep an array in
> memory so that it doesn't have to be
> reloaded each time a .php script is run.
>
> Is this possible?
>
> In Java, I could load the array from a file
> in the init() method of a servlet and it would
> stay in memory until the server is shutdown
> or restarted, etc.
>
> Thanks,
>
> Andrew
>
>

Andrew,

Unlike in a Java servlet environment, arrays in PHP are not kept in
memory. All objects created by your script are destroyed at the end of
execution. So, once your script is done loading the page, all data
stored in memory is marked for garbage collection. You will have to
store your data structures (I am assuming you want to save persistent
data) in a database, flat file, or any other location that is to your
liking.

Amir.

-- 
Rules are written for those who lack the ability to truly reason, But for
those who can, the rules become nothing more than guidelines, And live
their lives governed not by rules but by reason.
      - James McGuigan


Relevant Pages

  • Re: Keeping an Array in Memory
    ... > reloaded each time a .php script is run. ... Christopher's suggestion to store an array in a ... array is only loaded when a session starts and can be accessed ... from memory as long as the session is maintained. ...
    (comp.lang.php)
  • Re: Persistence data
    ... I need to store this variable in memory for performance reasons ... deserializing a large array from a file at run time started to pay off ... While you could write own PHP appserver daemon to process this (IIRC ... Answer is to do it at the database tier. ...
    (comp.lang.php)
  • Keeping an Array in Memory
    ... I'm afraid I don't know PHP well enough ... reloaded each time a .php script is run. ... I could load the array from a file ... stay in memory until the server is shutdown ...
    (comp.lang.php)
  • Re: Performance inquiry
    ... you wouldn't have the array ... > just sitting in memory. ... PHP is not C after all. ...
    (comp.lang.php)
  • Searching an Array
    ... Is there a quick search function in PHP ... I have an array of 1000 elements and I just ... Andrew ...
    (comp.lang.php)