Php java in memory database

I need to load data as an array into memory in PHP.but in PHP if I write $ array = array ("1", "2"); in test.php, then this $ array variable is initialized every time the user requests. If we request test.php 100 times by clicking the update reset button 100 times, then this $ array variable will be executed 100 times.

but I need to execute the $ array variable only once for the first time request, and the subsequent test.php request should not execute the $ array variable. But use only this memory location. How can I do this in PHP.

but in JAVA SEVRVLET is easy to execute, just write the $ array variable at a time when you run the init () method of the servlet lifecycle method and then request that servlet not run the init () method, but the service () method, but service () always uses this Array location $ array.

all I want to initialize the $ array variable once, but use this memory object from a subsequent request in PHP. Is there any possibility in PHP?

+3
source share
5 answers

PHP , Java Servlet. PHP, ( , ),

, , memcached PHP " ", memcached , . , ( ) PHP.

+3

, test.php

<?php
session_start();

if(!isset($_SESSION['user_action'])){ $_SESSION['user_action'] = array("1","2"); } ?>

, ​​ "user_action", , ​​ .

.

+1

All variables are destroyed when the request is completed, there is no built-in mechanism for doing what you want in php.

+1
source

PHP has a different kind of execution.
In general, this is not possible in PHP, and this is normal.

0
source

You can try the following:

<?php
/* test.php */
if (empty($GLOBALS['array'])) {
    $GLOBALS['array'] = array("1", "2");
}
?>
-2
source

Source: https://habr.com/ru/post/1743980/


All Articles