Solved

PHP forked process referring to parent process variables

Posted on 2003-11-11
8
328 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

813 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