CodeIgniter Forums
shared memory? How to share an array? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: shared memory? How to share an array? (/showthread.php?tid=76973)



shared memory? How to share an array? - richb201 - 07-09-2020

My controller gets some data from DynamoDB into an array. I need to use that data in a MyReport.php file that is sitting in /assets. Is there anything analagous to "shared memory"?  My controller is loading up an array with data it got from dynamoDB. This array can be 1000 rows or more. If I make this array GLOBAL or push it into $_SERVER in my controller, will I be able to access it from /assets/MyReport.php? Any idea where to stick this array?


RE: shared memory? How to share an array? - jreklund - 07-09-2020

No, you can't share code that way. You need to access the same data from the database or save it in a temp file or using a cache engine like redis.


RE: shared memory? How to share an array? - richb201 - 07-09-2020

Thanks jr. I found that I can save the array data in $_SESSION[result] in the controller, and then access it in the /assets/MyReport.php by using $_SESSION[result] But i am concerned about sticking a large array into $_SESSION (right now I have 14 items). what will happen if I have 2 or 3 thousand? This is a multiuser system. Can I assume that $_SESSION is "safe between different users?


RE: shared memory? How to share an array? - jreklund - 07-09-2020

In the same session you can store it like that, I thought you ment two different runtimes.

$_SESSION are unique to you, as long as they don't have your session cookie id, they can't access it. If they don't hack your application and grab it from there, but then you have other problems.

$_SESSION size are limited to PHP memory, and are stored serialized on file, so that's not something I would recommend. I would go for a cache engine instead, like redis or memcache.