Closed peter-gribanov closed 8 years ago
Not correctly generate a random id for the memory block. If the block will be to use multiple processes they will need to know the id to access the data. If the memory block will be used only in the current execution of the program, it is best to use a shared variable, and point in using SHMOP disappears.
In your example: $memory = new Block(123); $memory->write('foo'); unset($memory);
// new object $memory = new Block(123); $this->assertEquals('foo', $memory->read());
The unset($memory) will imply a call to the destructor an he removes the shared_memory segment.
If you remove the destructor from the code, it shall work. But you'll have to invent a cleaning method to replace this destructor removal.
@cfilippe you are wrong. Shmop_close function does not remove the memory segment. To erase function is used shmop_delete.
In this task, I'm not talking about the problem of removing the data. I talking the problem of data transfer to another php process in the case of generation the unique ID of the block.
$memory = new Block();
$memory->write('foo');
in a another php process trying to get the variable
$memory = new Block();
$this->assertEquals('foo', $memory->read());
We get an error because in the first and the second case are generated different ID. Transmission of data in such cases, perform fail. So, i talking that ID does not have to be generated, and always needs to be fixed.
Expanding SHMOP intended to two different PHP process had the opportunity to work with a common memory unit. Your library does not offer such opportunities. Simple tests show that.
The new process must be able to read data from the memory unit that could be filled by another process, or may not be filled.
Example transmitting data from one process to another.