Semaphore and Shared Memory Functions Semaphore This module provides semaphore functions using System V semaphores. Semaphores may be used to provide exclusive access to resources on the current machine, or to limit the number of processes that may simultaneously use a resource. This module provides also shared memory functions using System V shared memory. Shared memory may be used to provide access to global variables. Different httpd-daemons and even other programs (such as Perl, C, ...) are able to access this data to provide a global data-exchange. Remember, that shared memory is NOT safe against simultaneous access. Use semaphores for synchronization. Limits of Shared Memory by the Unix OS SHMMAX max size of shared memory, normally 131072 bytes SHMMIN minimum size of shared memory, normally 1 byte SHMMNI max amount of shared memory segments, normally 100 SHMSEG max amount of shared memory per process, normally 6
These functions do not work on Windows systems.
sem_get Get a semaphore id Description int sem_get int key int max_acquire int perm Returns: A positive semaphore identifier on success, or false on error. Sem_get returns an id that can be used to access the System V semaphore with the given key. The semaphore is created if necessary using the permission bits specified in perm (defaults to 0666). The number of processes that can acquire the semaphore simultaneously is set to max_acquire (defaults to 1). Actually this value is set only if the process finds it is the only process currently attached to the semaphore. A second call to sem_get for the same key will return a different semaphore identifier, but both identifiers access the same underlying semaphore. See also: sem_acquire and sem_release. This function does not work on Windows systems sem_acquire Acquire a semaphore Description int sem_acquire int sem_identifier Returns: true on success, false on error. Sem_acquire blocks (if necessary) until the semaphore can be acquired. A process attempting to acquire a semaphore which it has already acquired will block forever if acquiring the semaphore would cause its max_acquire value to be exceeded. After processing a request, any semaphores acquired by the process but not explicitly released will be released automatically and a warning will be generated. See also: sem_get and sem_release. sem_release Release a semaphore Description int sem_release int sem_identifier Returns: true on success, false on error. Sem_release releases the semaphore if it is currently acquired by the calling process, otherwise a warning is generated. After releasing the semaphore, sem_acquire may be called to re-acquire it. See also: sem_get and sem_acquire. This function does not work on Windows systems shm_attach Creates or open a shared memory segment Description int shm_attach int key int memsize int perm Shm_attach returns an id that that can be used to access the System V shared memory with the given key, the first call creates the shared memory segment with mem_size (default: sysvshm.init_mem in the configuration file, otherwise 10000 bytes) and the optional perm-bits (default: 0666). A second call to shm_attach for the same key will return a different shared memory identifier, but both identifiers access the same underlying shared memory. Memsize and perm will be ignored. This function does not work on Windows systems shm_detach Disconnects from shared memory segment Description int shm_detach int shm_identifier Shm_detach disconnects from the shared memory given by the shm_identifier created by shm_attach. Remember, that shared memory still exist in the Unix system and the data is still present. shm_remove Removes shared memory from Unix systems Description int shm_remove int shm_identifier Removes shared memory from Unix systems. All data will be destroyed. This function does not work on Windows systems shm_put_var Inserts or updates a variable in shared memory Description int shm_put_var int shm_identifier int variable_key mixed variable Inserts or updates a variable with a given variable_key. All variable-types (double, int, string, array) are supported. This function does not work on Windows systems shm_get_var Returns a variable from shared memory Description mixed shm_get_var int id int variable_key Shm_get_var returns the variable with a given variable_key. The variable is still present in the shared memory. This function does not work on Windows systems shm_remove_var Removes a variable from shared memory Description int shm_remove_var int id int variable_key Removes a variable with a given variable_key and frees the occupied memory. This function does not work on Windows systems