Solved

PHP forked process referring to parent process variables

Posted on 2003-11-11
8
326 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 11

Expert Comment

by:shmert
Comment Utility
How about java?
0
 
LVL 14

Expert Comment

by:ThG
Comment Utility
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
Comment Utility
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
Comment Utility
PAQ'd & 500 points refunded

Chmod
Community Support Moderator @ Experts Exchange
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
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.

772 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

11 Experts available now in Live!

Get 1:1 Help Now