Solved

PHP forked process referring to parent process variables

Posted on 2003-11-11
8
327 Views
Last Modified: 2010-08-05
I have written a multi-thread (process) socket server script. It consists of a Listener class (one process) and XMLSocket class (separate client processes). The problem is that I cannot refer from the XMLSocket process back to the Listener process the socket array or any of its variables. Once the Listener spawns a new child/connection, the Listener class variables can be passed on to the XMLSocket class as 'copy' only but not by reference. Hence the spawned children/connection will not know of any later changes in the Listener client array or any of the Listener's variable but only the 'status' of the Listener at the time of the process is forked. I would need to have the spawned connections refer back to the parent process variables since I may use this as a chat server, hence each child has to be able to refer to the 'parent' list of spawned connections for communication.

I guess this is the difference between multi-thread and mutli-process. However, I would like to know if there is a way to work around this problem. Answers telling me to use other programming languages are not accepted. The scope of this question covers PHP only.
0
Comment
Question by:bjai
8 Comments
 
LVL 11

Expert Comment

by:shmert
ID: 9732268
I don't think you'll get pass-by-reference working between processes, since the variables passed back and forth are dealing with totally different locations in memory.  One cheesy way to do this would be to serialize() your object to a file, and then notify some other thread that the object has changed, and to unserialize() it.
0
 
LVL 1

Author Comment

by:bjai
ID: 9732911
Hmm, but the socket handle/resources cannot be stored in an external file/memory? It can't be serialized anyway?

I had in mind maybe using shared memory functions but still such method can only be invoked by the parent process and the child process can't do much to 'fetch' things from the parent. Say the parent process has created 1000 child process/connection, the parent process has to run a non-blocking select and loop thru the 1000 child processes to update them. Even then, there will be delay in the 'parent status'  of each of the child processes and this gets worse as more children are spawned. Also this will take up quite a lot of resources also, each child process stores its own copy of the parent process data. So afterall, it all gets very messy in terms of coding.

I have thin knowledge about linuxthreads (e.g. clone() ), maybe that is useful?

0
 
LVL 1

Author Comment

by:bjai
ID: 9732966
I have decided to award the points if someone can provide a C++ code example of the 'Listener' and 'child socket' threads OR provide a detailed approach using PHP (no code required). I realize that this question is not an easy one (in PHP), I understand PHP has its limitation, but maybe this is a good brain teaser for those PHP developers out there :)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:shmert
ID: 9733189
How about java?
0
 
LVL 14

Expert Comment

by:ThG
ID: 9736329
bjai, keep this question open, i want to give it a try tomorrow. Do you have something (client/server code) to work on?
0
 
LVL 1

Author Comment

by:bjai
ID: 9736882
I have some php source code but it's not fully functional as there is limitation as mentioned above. I am quite happy to send it out. But its quite long and consist of serveral class files so would only email it.
0
 

Accepted Solution

by:
Chmod earned 0 total points
ID: 9768326
PAQ'd & 500 points refunded

Chmod
Community Support Moderator @ Experts Exchange
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now