Jump to content

allamovec

Recommended Posts

Iam working on a multi-users online game and the scenario is :-

 

1- I fork a new process for each connection

 

2- first i stared with making a shared object with (unix sockets) , this object was containing the shared data among the process (ie: this object was the responsible for intercommunication between the processes

 

3-But i notice that there is al ot of errors on the data returned from the shared objects (unexpected data).

 

4- so i separated my code and start to depend only on memcache(with 1024 storage capacity) to transfer objects among the processes.

 

5- the users can play with each other in a specific room.

 

5-each user has on object(instance of player class) in the memcache

 

6-each room has an object(instance of room class) in the memcache

 

The problem is : -

 

all is ok if there is a few number of players in the server but

If there is a lot of players in the server the memcache produce an error

 

 

Memcache::get(): Server localhost (tcp 11211) failed with: Malformed VALUE header (0)

Memcache::replace(): Server localhost (tcp 11211) failed with: Received malformed response (0)

Memcache::get(): Server localhost (tcp 11211) failed with: Failed reading line from stream (0)

 

 

 

and some times the memcache return to me an object of player instead of object of room :(

 

 

ex:

$memcache->get("player1") should return an object for a player class but it sometime return an object for a room class

$memcache->get("room1") should return an object for a room class but it sometime return an object for a player class

 

 

 

i did not know what is the problem

Link to comment
Share on other sites

I've dabbled with this kind of thing in PHP and I'll tell you: it's not easy. The best method I know is IPC (inter-process communication) such as with streams (essentially sockets but they're easier to deal with in PHP than sets of sockets). Shared memory is only worthwhile if one process ever writes to it and all the other processes read.

Not to mention how the whole Unix forking model is such a hassle compared to Windows' threading model. Want a second thread? Fork the whole damn process and clean up memory you don't need to use.

 

If you're really serious about this then don't use PHP for it. Or at least not all of it. It just doesn't support multithreading that well.

Link to comment
Share on other sites

yes i know that php do not support multithreading but i tried to work around this problem by making multiprocess with shared object (using stream_socket_pair ) .

 

 

1- the master(mp) process is the parent for all forked process (p1,p2,p3,p4,p5,p6...... etc)

2- if p1 want to communicate with p2 it should leave a message for p2 at the master process . (ie: the master process will act as the container which all processess read and write from it ),

the communication between the processes is indirect (it will be via the master process). but the master process sometime returned invalid data (may be because the load on the server).

 

finally i decided to use java for the backend not php :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.