The memory footprint of some global vals

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

    The memory footprint of some global vals

    Hi,

    Just like phpBB i have a fairly large language section.

    For those of you who do not know it there is a global array variable $lang
    and it contains translations of many word used all over the place.
    For example
    $lang['hello'] = 'Hello';
    $lang['bye']='Goodbye';
    ....and so on

    but that array contains a few hundred entries, most of them are not used in
    the everyday use of the site.

    How big of a problem could that be in terms of memory? Does php load that
    array everytime a new user queries a page or is the array shared between all
    the processes?
    Would there be a better way of doing it that would not be so heavy on the
    memory?

    Regards.

    Sims


  • CountScubula

    #2
    Re: The memory footprint of some global vals

    if it is in an include file, chances are the files is in cached in ram, and
    generaly speaking, the data is not a shared memory object, it can be one
    memory object shared by all proccesses, but there is a good chance its not.

    to ease the load, in either case just put $100 in memory and call it a day.



    --
    Mike Bradley
    http://www.gzentools.com -- free online php tools
    "Sims" <siminfrance@ho tmail.com> wrote in message
    news:c0pmhf$1a6 1lh$1@ID-162430.news.uni-berlin.de...[color=blue]
    > Hi,
    >
    > Just like phpBB i have a fairly large language section.
    >
    > For those of you who do not know it there is a global array variable $lang
    > and it contains translations of many word used all over the place.
    > For example
    > $lang['hello'] = 'Hello';
    > $lang['bye']='Goodbye';
    > ...and so on
    >
    > but that array contains a few hundred entries, most of them are not used[/color]
    in[color=blue]
    > the everyday use of the site.
    >
    > How big of a problem could that be in terms of memory? Does php load that
    > array everytime a new user queries a page or is the array shared between[/color]
    all[color=blue]
    > the processes?
    > Would there be a better way of doing it that would not be so heavy on the
    > memory?
    >
    > Regards.
    >
    > Sims
    >
    >[/color]


    Comment

    • Sims

      #3
      Re: The memory footprint of some global vals

      [color=blue]
      > if it is in an include file, chances are the files is in cached in ram,[/color]
      and[color=blue]
      > generaly speaking, the data is not a shared memory object, it can be one
      > memory object shared by all proccesses, but there is a good chance its[/color]
      not.[color=blue]
      >
      > to ease the load, in either case just put $100 in memory and call it a[/color]
      day.[color=blue]
      >
      >[/color]

      Thanks, but it is not a case of money, more a case of me wanting to learn
      how it works.
      If i can prevent the 'over' use of memory that would be better programming i
      think.

      It is a include file.
      I just wanted to know the inner workings of php and how global variables are
      affecting my memory.

      BTW i do not use $, (NZ, CAN, US or AUS whichever you were referring to).

      Regards,
      Sims


      Comment

      • CountScubula

        #4
        Re: The memory footprint of some global vals

        "Sims" <siminfrance@ho tmail.com> wrote in message
        news:c0q033$19q o0c$1@ID-162430.news.uni-berlin.de...[color=blue]
        >[color=green]
        > > if it is in an include file, chances are the files is in cached in ram,[/color]
        > and[color=green]
        > > generaly speaking, the data is not a shared memory object, it can be one
        > > memory object shared by all proccesses, but there is a good chance its[/color]
        > not.[color=green]
        > >
        > > to ease the load, in either case just put $100 in memory and call it a[/color]
        > day.[color=green]
        > >
        > >[/color]
        >
        > Thanks, but it is not a case of money, more a case of me wanting to learn
        > how it works.
        > If i can prevent the 'over' use of memory that would be better programming[/color]
        i[color=blue]
        > think.
        >
        > It is a include file.
        > I just wanted to know the inner workings of php and how global variables[/color]
        are[color=blue]
        > affecting my memory.
        >
        > BTW i do not use $, (NZ, CAN, US or AUS whichever you were referring to).
        >
        > Regards,
        > Sims[/color]

        sorry, I was not insuating it was a case of money, my apologies. (oh, and
        the $=US, sorry, I forget this is read all over the world)

        With scripting, it is a slightly differnt animal compared to
        compiling/binary programming. some times in scripting it is the easyier
        route that shall prevail.

        Now I do undstand your curiosity.

        It is possible with php to create a shared memory object (works like a file)
        that would hold all items in your lang definitions, then this can be
        available to all proccess.

        But becouse we are dealing with more than just the PHP interpeter, such as
        the OS, file system, I have found that included files that are used in every
        single script (such as variable definitions/configs) tend to get cached by
        the OS into memory, granted, they go from their cached copy to a new copy
        for each process, it is rather fast. Also with less overhead on the
        programming side of the fence. With the expense of a bit more memory, it
        just be comes an include, but with it as as shared memory object, you then
        have code to access such object, and a bit more complexity.

        It is my opinion, that sometimes, an easier to read/modify script is a faste
        r/econamical slotution. Now I am not advicating sloppy coding skills, In
        fact, I come from a background where I would have to cram in an OS,
        aplication, and data into a 2K ROM chip, not fun, but made for some crafy
        coding (whitch I do miss sometimes)

        Well, sorry to ramble on, I know I probly didn't answer your question, but I
        hope I brought up some stuff to ponder.

        --
        Mike Bradley
        http://www.gzentools.com -- free online php tools


        Comment

        • Sims

          #5
          Re: The memory footprint of some global vals

          [color=blue][color=green]
          > >
          > > Regards,
          > > Sims[/color]
          >
          > sorry, I was not insuating it was a case of money, my apologies. (oh, and
          > the $=US, sorry, I forget this is read all over the world)[/color]

          No worries, :)
          [color=blue]
          >
          > It is possible with php to create a shared memory object (works like a[/color]
          file)[color=blue]
          > that would hold all items in your lang definitions, then this can be
          > available to all proccess.[/color]

          But would it really be better.
          [color=blue]
          >
          > But becouse we are dealing with more than just the PHP interpeter, such as
          > the OS, file system, I have found that included files that are used in[/color]
          every[color=blue]
          > single script (such as variable definitions/configs) tend to get cached by
          > the OS into memory, granted, they go from their cached copy to a new copy
          > for each process, it is rather fast. Also with less overhead on the
          > programming side of the fence. With the expense of a bit more memory, it
          > just be comes an include, but with it as as shared memory object, you then
          > have code to access such object, and a bit more complexity.[/color]

          I see,
          [color=blue]
          >
          > It is my opinion, that sometimes, an easier to read/modify script is a[/color]
          faste[color=blue]
          > r/econamical slotution. Now I am not advicating sloppy coding skills, In
          > fact, I come from a background where I would have to cram in an OS,
          > aplication, and data into a 2K ROM chip, not fun, but made for some crafy
          > coding (whitch I do miss sometimes)[/color]

          I also had the pleasure of putting 16k code on the chip of some credit card
          companies.
          A similar challenge in itself.
          [color=blue]
          >
          > Well, sorry to ramble on, I know I probly didn't answer your question, but[/color]
          I[color=blue]
          > hope I brought up some stuff to ponder.[/color]

          You did, thanks.
          [color=blue]
          >
          > --
          > Mike Bradley[/color]

          Sims


          Comment

          Working...