Is there a way in PHP to use persistent data as in Java EE? (sharing objects between PHP threads) without session nor cache/DB

前端 未结 4 704
广开言路
广开言路 2020-12-06 18:43

Is there a way in PHP to use \"out of session\" variables, which would not be loaded/unloaded at every connexion, like in a Java server ?

Please excuse me for the la

4条回答
  •  孤城傲影
    2020-12-06 19:09

    Another solution is to wrap your variable in a "persistent data" class that will automatically restore its data content every time the php script is run. Your class needs to to the following:

    • store content of variable into file in __destructor
    • load content of variable from file in __constructor

    I prefer storing the file in JSON format so the content can be easily examined for debugging, but that is optional.

    Be aware that some webservers will change the current working directory in the destructor, so you need to work with an absolute path.

提交回复
热议问题