How to write more than 1 strings to shared memory using shmop_write php? -
i'm pretty new here , need help. know how write more 1 strings shared memory using shmop_write php?
this php syntax:
$key = 864; $mode = 'c'; $permission = 0644; $size = 1024; $shmid = shmop_open($key, $mode, $permission, $size); $string = "this string 1"; $string2 = "string 2"; shmop_write($shmid, $string, 0); shmop_write($shmid, $string2, 0); $size = shmop_size($shmid); echo shmop_read($shmid, 0, $size); shmop_delete($shmid); shmop_close($shmid); expected result (wanted result) : this string 1string 2
but, the result of syntax : string 2string 1
and if alter $string = "string 1" $string = "this string 1", result still : string 2string 1 (like can't refresh memory block)
can tell me how wanted result? thx.
shared memory not stream, it's block of memory. 3rd argument shmop_read() specifies in memory block write should happen. if write same offset, overwrites there before. if want write 1 thing after another, need specify different offset:
shmop_write($shmid, $string, 0); shmop_write($shmid, $string2, strlen($string)); if want write lots of things shared memory, update variable track current position:
$offset = 0; shmop_write($shmid, $string, $offset); $offset += strlen($string); shmop_write($shmid, $string2, $offset); $offset += strlen($string2); shmop_write($shmid, $string3, $offset); $offset += strlen($string3); shmop_write($shmid, $string4, $offset); $offset += strlen($string4); a thought implement using class, $offset class property.
php string shared-memory
No comments:
Post a Comment