parallel icon indicating copy to clipboard operation
parallel copied to clipboard

Is possible to share data from main process to workers?

Open aloumpas opened this issue 3 years ago • 4 comments

I would like to know is it possible to create, lets say an array, on the main process and then read this inside workers without copying the entire array inside worker. Also i would like to know if it possible from workers to write on shared variables on the main process

aloumpas avatar Aug 27 '21 15:08 aloumpas

No and no. They're separate processes. They don't have any kind of shared memory.

You can of course put the data into a database or something.

enumag avatar Aug 27 '21 16:08 enumag

Not by using variables, but you can post messages.

Bilge avatar Aug 27 '21 16:08 Bilge

Yeah... to accessing that array you would have to implement a mechanism for the child to ask the parent for a value and the parent to correctly respond to the request using the channel send/receive methods... https://amphp.org/parallel/processes

enumag avatar Aug 27 '21 16:08 enumag

My amphp IPC library might help vere: https://github.com/danog/ipc

danog avatar Sep 05 '21 10:09 danog

I believe this question has been answered, so I'm closing it. Please open a new issue if you have any further questions. 👍

trowski avatar Dec 30 '22 01:12 trowski