kakki wrote:
- is there a way to keep objects after the page is rendered ?
No, there is not. PHP uses a shared-nothing model which does not allow any persistent data to be held in memory or shared memory.
You can of course persist objects into a file or database (or indeed, session which is just a special case of one of these), in which case they would have to be disassembled (e.g. by an ORM) or serialised.
- what about connection pooling, is there something for that ?
Connection pooling is a form of shared object. You should not need it. Just create a new connection on each page and let it be destroyed at the end. This does not normally create a major performance problem, but if your profiling data tells you that it is doing so, consider (carefully) using persistent connections once you understand all the issues and have load-tested your system.
- now what about 2 threads running simultanously, are there means for that ???
Two PHP requests can run at once. Depending on the web server, they may run in separate threads or separate processes. It really is up to the implementation what actually happens.
There is no native way of creating threads in PHP, but in some cases your code will run in a threaded environment.
If you need to do background tasks, I recommend creating daemon process(es) as necessary and having them communicate somehow.
Using threads explicitly requires care as it can be error-prone. PHP generally shields you from this kind of stuff.
In any case, developing on the assumption that there are shared objects between web server threads is naive, because your solution WILL NOT SCALE.
Even in Java, the shared objects will only be shared with other threads in the same process, not other processes, let alone other machines. A scalable web application will run on multiple machines out of NECESSITY.
Therefore, you can't really use them for anything important.
Of course some Java app servers support horrible protocols for trying to sychronise (serialisable) shared objects between servers in a pool - this is a bit icky. Try to avoid it. I can't imagine the performance of such a system being desirable.
Likewise, if you can avoid using sessions, that's even better as it reduces the coupling of your servers (a session must be locked so that other threads don't use it at the same time; this locking obviously creates contention) and therefore increases scalability.
Mark