From e601e730fa7a5e99c3c21c3459f102beb6d31e50 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Sun, 1 Oct 2000 15:09:15 +0000 Subject: [PATCH] - Documentation for the shmop functions. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@33223 c90b9560-bf6c-de11-be94-00142212c4b1 --- chapters.ent | 1 + functions/shmop.xml | 331 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 332 insertions(+) create mode 100755 functions/shmop.xml diff --git a/chapters.ent b/chapters.ent index 512342fa15..4029b70680 100644 --- a/chapters.ent +++ b/chapters.ent @@ -88,6 +88,7 @@ + diff --git a/functions/shmop.xml b/functions/shmop.xml new file mode 100755 index 0000000000..b7883d5fbb --- /dev/null +++ b/functions/shmop.xml @@ -0,0 +1,331 @@ + + Shared Memory Functions + shmop + + + + Shmop is an easy to use set of functions that allows php to read, + write, create and delete UNIX shared memory segments. The functions + will not work on windows, as it does not support shared memory. To + use shmop you will need to compile php with the --enable-shmop parameter + in your configure line. + + + + Shared Memory Operations Overview + +<?php + +// Create 100 byte shared memory block with system id if 0xff3 +$shm_id = shm_open(0xff3, "c", 0644, 100); +if(!$shm_id) { + echo "Couldn't create shared memory segment\n"; +} + +// Get shared memory block's size +$shm_size = shm_size($shm_id); +echo "SHM Block Size: ".$shm_size. " has been created.\n"; + +// Lets write a test string into shared memory +$shm_bytes_written = shm_write($shm_id, "my shared memory block", 0); +if($shm_bytes_written != strlen("my shared memory block")) { + echo "Couldn't write the entire length of data\n"; +} + +// Now lets read the string back +$my_string = shm_read($shm_id, 0, $shm_size); +if(!$my_string) { + echo "Couldn't read from shared memory block\n"; +} +echo "The data inside shared memory was: ".$my_string."\n"; + +//Now lets delete the block and close the shared memory segment +if(!shm_delete($shm_id)) { + echo "Couldn't mark shared memory block for deletion. +} +shm_close($shm_id); + +?> + + + + + + + + shm_open + Create or open shared memory block + + + Description + + + int shm_open + int key + string flags + int mode + int size + + + + shm_open can create or open a shared memory block. + + + shm_open takes 4 parameters: key, which is the + system's id for the shared memory block, this parameter can be passed + as a decimal or hex. The second parameter are the flags that you can use: + + + + "a" for access (sets IPC_EXCL) + use this flag when you need to open an existing shared memory segment + + + + + "c" for create (sets IPC_CREATE) + use this flag when you need to create a new shared memory segment. + + + + The third parameter is the mode, which are the permissions that you + wish to assign to your memory segment, those are the same as permission + for a file. Permissions need to be passed in octal form ex. 0644. + The last parameter is size of the shared memory block you wish to create + in bytes. + + Note: the 3rd and 4th should be entered as 0 if you are opening an + existing memory segment. On success shm_open will + return an id that you can use to access the shared memory segment + you've created. + + + + + Create a new shared memory block + +<?php +$shm_id = shm_open(0x0fff, "c", 0644, 100); +?> + + + + + This example opened a shared memory block with a system id of 0x0fff. + + + + + + + shm_read + Read data from shared memory block + + + Description + + + string shm_read + int shmid + int start + int count + + + + shm_read will read a string from shared memory block. + + + shm_read takes 3 parameters: shmid, which is the shared + memory block identifier created by shm_open, offset from + which to start reading and count on the number of bytes to read. + + + + Reading shared memory block + +<?php +$shm_data = shm_read($shm_id, 0, 50); +?> + + + + + This example will read 50 bytes from shared memory block and place the data + inside $shm_data. + + + + + + + shm_write + Write data into shared memory block + + + Description + + + int shm_write + int shmid + string data + int offset + + + + shm_write will write a string into shared memory block. + + + shm_write takes 3 parameters: shmid, which is the + shared memory block identifier created by shm_open, + data, a string that you want to write into shared memory block and offset, + which specifies where to start writing data inside the shared memory segment. + + + + Writing to shared memory block + +<?php +$shm_bytes_written = shm_write($shm_id, $my_string, 0); +?> + + + + + This example will write data inside $my_string into + shared memory block, $shm_bytes_written will contain + the number of bytes written. + + + + + + + shm_size + Get size of shared memory block + + + Description + + + int shm_size + int shmid + + + + shm_size is used to get the size, in bytes of the + shared memory block. + + + shm_size takes the shmid, which is the shared memory + block identifier created by shm_open, the function + will return and int, which represents the number of bytes the shared memory + block occupies. + + + + Getting the size of the shared memory block + +<?php +$shm_size = shm_size($shm_id); +?> + + + + + This example will put the size of shared memory block identified by + $shm_id into $shm_size. + + + + + + + shm_delete + Delete shared memory block + + + Description + + + int shm_delete + int shmid + + + + shm_delete is used to delete a shared memory block. + + + shm_delete takes the shmid, which is the shared memory + block identifier created by shm_open. On success 1 is + returned, on failure 0 is returned. + + + + Deleting shared memory block + +<?php +shm_delete($shm_id); +?> + + + + + This example will delete shared memory block identified by + $shm_id. + + + + + + + shm_close + Close shared memory block + + + Description + + + int shm_close + int shmid + + + + shm_close is used to close a shared memory block. + + + shm_close takes the shmid, which is the shared memory + block identifier created by shm_open. + + + + Closing shared memory block + +<?php +shm_close($shm_id); +?> + + + + + This example will close shared memory block identified by $shm_id. + + + + + +