tags:

views:

120

answers:

6

Hi,

I have a php script and i want to store some information in RAM. The information should be accessible 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.

A: 

I don't think that PHP can access the computer RAM. But you could store the informatio in a session variable or a cookie.

danilo
So what sort of memory is PHP using when running?
php can access RAM. try fopen on a php://temp filestream, or shmop_open( ) functions.
Timothy
Ah, didn't know about that. Thanks for the information. @MrXexxed, of course I knew that the PHP interpreter can access the memory, but I didn't know that there are any functions that allow the user to manually address and access specific memory blocks.
danilo
I'll accept that explanation but that isn't what your answer says, call me a pedant but I'm not a mind-reader there's nothing about the user in your answer, just PHP. I can only judge your answer based on what you write not a guess on what you *might* know.
If the question is about a script that he's writing, to me it's very obvious that the answers will be about php usage and it's functions, and not about the php interpreter and how it works. But I don't want to argue, I posted a wrong information, and I'm sorry for it.
danilo
A: 

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)

knittl
+4  A: 

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/

Klaas van Schelven
A: 

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)

Dragos
A: 

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

Brent Baisley
A: 

1)Memcached
2)Mysql table with Memory engine.

codez