This is not a complete answer; but he comes up to the answer.
As already mentioned, advertising advertisements elsewhere, the standard classical model of using PHP via a web server (Apache, Nginx, etc.) does not allow you to do this, because each hacking of a page starts with a completely new set of variables.
Three thoughts:
- You need a persistence layer. Obviously, here you are storing material in a database or using APC ( APCu in PHP7 +), Redis, or something similar.
However, your problem is that you specify "unserializable".
My next suggestion would be, perhaps you could save the elements needed to create the object and reinitialize the object for each PHP request. It will not be as surprising as you would like, but it is the most useful solution without rewriting eveything. You may have already tried this.
The next step is to do something completely out. One of the advantages of the NodeJS infrastructure is that the entire server cycle is maintained.
So, you can try one of the alternative methods for starting PHP, for example ReactPHP or PHP FastCGI . (There are others, but I canβt remember them from my head. I will edit this if I remember.)
This implies a completely different way of writing PHP - the same as programming NodeJS - this is the overlay of jQuery inside your browser. It will not work in Apache. Rather, it will run directly as an application on your Unix server. And you will need to handle things like garbage collection so you don't have memory leaks, and write nice hard event loops.
The positive side is that your thread is saved and processes each subsequent request, you can process requests exactly as you do after.
source share