How many instances of one class are on the server?

Is it possible to find out how many instantiated objects of one PHP class exist on the server (for all users, and not just for one thread).

That is why I want to do this. I am making a card game, and I want to have a room class (with a unique room name, the players are currently online in the room, id sock ...), so when some users join the server to have a fresh list of active rooms. And when one room is canceled (destroyed), I would send this information to all users (basically the status of the room in real time).


Well, that’s why I want to do this. I am doing a card game project and I want to have a room class (with a unique room name, the players are currently online in the room, id sock ...), so when some users join the server to have a fresh list of active rooms. And when one room is canceled (destroyed), I would send this information to all users (basically the status of the room in real time). I hope you understand what I want to do.

+5
source share
3 answers

You want to implement a multiplayer game, so you should use a client-server architecture for it . Set up a single, consistent server process, . "" PHP , .

, Room : . - ( ) , .

, , ( ). . , - .

:. , PHP. PHP, , . , 5 , . -. PHP, . , . . , - , .

2:. , , , : :

php . - , php script , . ( , ), , . . . ( ) , .

concurrency? , , : script . , , , . , -, , -.

+4

, - . -, - , - , .....

, , - ...

( ) , , / . / .., , .

+2

- . - , php, gdb ( - ) . , .

: ? , , -.

You may be able to avoid the simple use of the APC increment and decrement when creating and destroying objects, but if in fact there are so many such objects that you need to count them, then you can definitely cause a big performance problem.

0
source

All Articles