PHP global array as temporary table

2

I'm in the middle of a problem, I'd like to use a array as a temporary table, more or less like this:

$array = [
    "codigo"    => "0123",
    "descricao" => "produto"
];

But I would need it to be global , but I have many doubts, can this be too heavy on the server? Are global variables conflicting with clients, or are they like sessions, and are they not shared between hits?

And I would also like to ask you an example of how to use global arrays.

Thank you in advance

    
asked by anonymous 13.10.2016 / 15:13

2 answers

1

It will weigh and danger even to topple your server (I already made this mistake). Create a cookie with the data and use the cookie when you need it, or write to a database. Session and global variables serve to make it easier to maintain and store configuration variables, so use only when it's really needed.

    
13.10.2016 / 15:31
1

You can use a .txt file to save your data.

$nome_arquivo = 'arquivo_temp_'.time().'.txt';
$_SESSION['arquivo_temp'] = $nome_arquivo;

$fp = fopen($nome_arquivo,'w+');
fwrite($fp,$dados_a_armazenar);

You can save the data in the .txt file and then retrieve the data at any time.

$nome_arquivo = $_SESSION['arquivo_temp'];
$fp = fopen($nome_arquivo,'r');

To delete the file you can delete when the user exits the system, or you can create a function that deletes the files after X time.

    
13.10.2016 / 15:43