Reduce memory size of my PHP array -


i've come across problem of large memory size of php arrays. i'm trying store small amount of data per object, in bunch of small arrays. storage looks this.

[stats] => array      (     [apps] => array             (                 [career] => array                     (                         [0] => 0                         [1] => 0                         [2] => 0                         [3] => 0                         [4] => 0                         [5] => 0                     )                  [team] => array                     (                         [0] => 0                         [1] => 0                         [2] => 0                         [3] => 0                         [4] => 0                         [5] => 0                     )                  [season] => array                     (                         [0] => 0                         [1] => 0                         [2] => 0                         [3] => 0                         [4] => 0                         [5] => 0                     )              )      [subapps] => array             (                 [career] => array                     (                         [0] => 0                         [1] => 0                         [2] => 0                         [3] => 0                         [4] => 0                         [5] => 0                     )                  [team] => array                     (                         [0] => 0                         [1] => 0                         [2] => 0                         [3] => 0                         [4] => 0                         [5] => 0                     )                  [season] => array                     (                         [0] => 0                         [1] => 0                         [2] => 0                         [3] => 0                         [4] => 0                         [5] => 0                     )              ) 

i need 20 or more of middle arrays shown here (e.g 'apps', 'subapps' etc). it's array of arrays of arrays, final arrays being 6 values long.

since it's 18 values, i'd assumed wasn't memory, i've found out php uses 144 bytes per value, it's turning out huge, since have 3000 such objects. it's using 30k per object, on 20 of these array blocks.

so i'm looking memory efficient solution. since final array 6 values, i'm thinking maybe can pack/unpack. looked splfixedarray doesn't suit needs in ways , doesn't save memory. want values show in readable format in database in case need edit them manually in db (one method tried saved memory values garbled in db).

update - solution. found simple solution this. arrays json_encode'd saving database. when load them, they're decoded. decoding whole batch @ once, hence massive memory usage, simple solution keep them encoded until needed, decode - process - encode. way, 1 ever decoded array , rest remain encoded, appears use small amounts of memory.


Comments