Resources and shared memory

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ody
Forum Contributor
Posts: 147
Joined: Sat Mar 27, 2004 4:42 am
Location: ManchesterUK

Resources and shared memory

Post by ody »

When setting up a shared memory variable it works as expected for strings, int, bool etc but resources are just assigned there resource id which is useless when accessed from another process. So after looking around the guts of PHP it looks like the only way around it is to create some form of get/set_resource functions that manage the actual resource not it's string id, something like:

Code: Select all

// parent process
$key = 1;
$fd = fopen('file');
$id = shm_attach($key);
shm_put_var($id, 1, get_resource($fd));
$ipc->msgSend($pid, $key);


//child process
$key = $ipc->msgRecv();
$id = shm_attach($key);
$fd = set_resource(shm_get_var($id, 1));
fread($fd, 1034);
Has anyone come across this problem before or have any alternative ideas before I start work on a patch?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

why would you want to share a resource (id) between separate processes? This just doesn't make sense to me.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Have you considered a HEAP table and object serialization?
ody
Forum Contributor
Posts: 147
Joined: Sat Mar 27, 2004 4:42 am
Location: ManchesterUK

Post by ody »

Weirdan wrote:why would you want to share a resource (id) between separate processes? This just doesn't make sense to me.
I don't, that was the point I was making. I want the actual behind the scenes descriptor. Anyway, I've come up with a work around to the problem.
Post Reply