Welcome Guest, Not a member yet? Register   Sign In
shared memory? How to share an array?
#1

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?
proof that an old dog can learn new tricks
Reply
#2

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.
Reply
#3

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?
proof that an old dog can learn new tricks
Reply
#4

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB