I have a shared memory region which I to want access with PHP running in a web server. The shared memory is laid out where the first 4 bytes is a 32-bit unsigned integer which contains how many bytes are valid data within the remaining shared memory region (the data can be variable size), i.e.:
Byte Range Value
------------------ -----------------------------------------------
0 - 3 32-bit unsigned integer - call it numBytes
4 - (numBytes + 4) char array - The actual data, total of numBytes
How do I read in the first four bytes as an integer? The only thing I can think of is do a shmop_read($key, 0, 4) and convert the returned string value to an array, then convert that array to an integer as described here. This all seems very messy and I was wondering if there is a cleaner way to do this?
unpack("V", shmop_read($key, 0, 4));. But could you post avar_dump(shmop_read($key, 0, 4));?unpack()I think your answer is correct. I will not be able to test it for a day or so; unfortunately. Could you give your comment as an answer because I cannot mark a comment as an answer.