Page 1 of 1

Resources and shared memory

Posted: Mon Dec 10, 2007 4:16 am
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?

Posted: Mon Dec 10, 2007 1:22 pm
by Weirdan
why would you want to share a resource (id) between separate processes? This just doesn't make sense to me.

Posted: Mon Dec 10, 2007 1:27 pm
by Kieran Huggins
Have you considered a HEAP table and object serialization?

Posted: Tue Dec 11, 2007 2:38 am
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.