SimpleSHM is a simple and small abstraction layer for shared memory manipulation using PHP. It makes use of the SHMOP functions, built into most PHP packages.
I believe there is a problem with this line:
$size = mb_strlen($data, 'UTF-8');
It returns the number of UTF-8 characters in $data. As UTF-8 is a multi-byte encoding, this number can vary from the actual length in bytes. This means the string would not fit into the reserved shared memory block.
The following fix would return the number of bytes:
$size = mb_strlen($data, '8bit');
Yes I wanted to say the same thing. You need the number of bytes not characters.
Also, only increase size if necessary. No need to shrink. Or put a threshold.
Hello Klaus,
I believe there is a problem with this line: $size = mb_strlen($data, 'UTF-8');
It returns the number of UTF-8 characters in $data. As UTF-8 is a multi-byte encoding, this number can vary from the actual length in bytes. This means the string would not fit into the reserved shared memory block.
The following fix would return the number of bytes: $size = mb_strlen($data, '8bit');
Best regards, gwyn