I am clear that to store any data in a globally persistent way so that it is accessible from any file in php, session variables must be used.
But apparently it can't store objects, only arrays and little else.
Is there a way to simulate this?
The object I have has variables that store open sockets and I think that can't be stored well.
You are really asking several questions simultaneously, some can be asked and some cannot.
Can an object be saved to a global super variable? Yes
Can an object be saved to a session variable? Yes
Can a resource be saved in a session variable? NO
Resources that can be used between different executions of PHP scripts cannot be saved because they are closed at the end of the execution, the file descriptors (among which are the sockets) are also released at the end of the execution, so they are not saved. they can reuse.
Connections to sockets or persistent databases
There is a lot of confusion on this topic: there are solutions to reuse previously established connections (such as TCP or UNIX sockets or connections to persistent databases ), but you are not guaranteed in any way that it will be the exact same connection that is used in the next one. time you connect.
If an attempt is made to open a socket or database connection that is already being used by another script, a new connection will be created to satisfy your script's need.
In the PHP documentation about persistent database connections you can read:
Answering your question, to store objects in memory you could use something like memcached :
But from what you put in the comments, the problem you have seems to be different from what you ask. You have a variable of type socket and you want it to be persistent. That's something you could perhaps achieve by opening the socket with
pfsockopen
(emphasis mine):It should be a UNIX domain socket though, which I don't know if that's the case for you.
I think you should use a database or a file (preferably the former).
You create a RAM table and do it there, the session is not a correct place to store large amounts of data.
This is the best way to make it persistent between different requests. You can use a session number to identify the user in question within these tables.