Keeping an Array in Memory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Amir Khawaja

    #16
    Re: Keeping an Array in Memory

    Andrea A wrote:[color=blue]
    > What about using sessions stored in memory?
    > Anyone use them?
    >
    > A.
    >
    >[/color]

    Sessions stored in memory are a good alternative. If you have some
    control over your server and the traffic to this webapp (website) is
    going to be high, you may want to investigate caching mechanisms like
    APC or any of the Zend caching products. I have used the Zend products
    and can safely say that it works. However, you may not want to invest in
    commercial tools as your need may not require the investment.

    Regards,
    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

    Comment

    • Zurab Davitiani

      #17
      Re: Keeping an Array in Memory

      Brad Kent wrote:
      [color=blue]
      > Zurab Davitiani <agt@mindless.c om> wrote in message[color=green]
      >> If you already use sessions, Christopher's suggestion to store an array
      >> in a session variable is a valid one:
      >>
      >> if(!$logged_in) // whatever your check
      >> $_SESSION["arr_stuff"] = get_array_from_ disk();
      >>[/color]
      >
      > That accomplishes nothing other than duplicating the array for every
      > user that accesses the page. The session data still hast to be loaded
      > each time the page is accessed. You _might_ see a performance
      > increase if you're storing session info in a DB, but the default is a
      > flat file. But I doubt it.. you're just creating more overhead.[/color]

      That is not completely accurate. It may still increase the performance if he
      *already uses sessions* since session data is already getting read and
      parsed from a file anyway for each request.
      [color=blue]
      > now instead of having a single "numbers.tx t" you've got it for every
      > session.[/color]

      You would have to open and parse numbers.txt for every request too. Storing
      the data in sessions will increase the disk space for sessions (depending
      on number of concurrent sessions and length of data), but will cut down on
      opening and closing one more file for each request. In either case,
      performance increase, if any, would be marginal. And I'd like to know
      myself which method is more efficient.
      [color=blue]
      > What the original guy is wanting is some sort of persistant memory..
      > doesn't exist. Just hope that your File I/O is intelligent and keeps
      > the frequently accessed "numbers.tx t" cached[/color]
      [color=blue][color=green]
      >> I'm not sure if this is your situation, but one thing that's not present
      >> in
      >> PHP is application-level variables since there is no concept of
      >> application. It would be nice to be able to keep certain
      >> application-level
      >> data in memory without having to read it from disk and/or keep the
      >> duplicates with every session; especially since this has been possible in
      >> ASP and with Java servlets for awhile.[/color][/color]

      How hard would it be to create something like a phpd that would keep
      configuration, application and application-level data in memory to be
      accessed by each PHP process?

      Comment

      Working...