Store information in RAM
I have a php script and i want to store some information in RAM. The information should be accessible 开发者_Python百科ONLY from my script and stored all time. What is best way to do that? What about globals arrays?
I want to do it for security reasons. No one can to get access to the information. For example If somebody hacks one of the my scripts they cannt to get access to the stored data.
I suppose you mean "store in RAM across various requests" since all variables in PHP (inside 1 script) are already stored in RAM. You should look into this (depending on the access you have to the server to install stuff / let someone install stuff)
http://memcached.org/
You can't store for all time in RAM, once the power goes out, it's gone. Usually you use something like memcache or APC. But, if you wanted to role you own solution, you can use shared memory and sempahores.
http://www.php.net/manual/en/book.shmop.php
http://php.net/manual/en/book.sem.php
there's no way around not using the RAM while executing a script. all your variables and objects will be allocated on the heap (which is in the RAM)
You could use APC, a pecl extension http://www.php.net/manual/en/intro.apc.php
Very stable, allows you to store pieces of info into a data store (closest thing to RAM). Faster than file storage or even databases. If you're running on a shared server you'll want to secure your data though (by a using a naming scheme or encryption)
1)Memcached
2)Mysql table with Memory engine.
I don't think that PHP can access the computer RAM. But you could store the informatio in a session variable or a cookie.
精彩评论