This is actually a group of three extensions to PHP that enable access to shared memory using the System V IPC (InterProcess Communication) model.
Note that this chapter is not intended to be an introduction to SysV IPC programming, so if you are new to the topic you may want to check out some web sites that address it. Much of the information available will deal with IPC in the C language, but the basic ideas can also be applied to IPC in PHP. A good introductory resource is Beej's Guide to Unix Interprocess Communication. A more advanced discussion is contained in Programming in C: UNIX System Calls and Subroutines Using C [A.D. Marshall, 1994-99].
The oldest of the three extensions are the semaphore ( sem_*() ) functions and the shared memory ( shm_*() ) functions, which are built into PHP using the --enable-sysvsem and --enable-sysvshm configure options, respectively.
The sem_*() functions provide cross-process locking of resources, allowing multiple processes to access the same shared memory block without interfering with each other. For instance, you might use semaphores to let other processes know that you're writing to a segment, so that they don't attempt to read or write to it at the same time.
The shm_*() functions use a special header format that's unique to PHP. This header allows scripts to store and retrieve data in key/value pairs, but also means that these segments will be more difficult to use in programs written in other languages.
The shmop_*() functions are the newest additions to PHP's shared memory functions. These functions are enabled by passing the --enable-shmop option to the configure script when building PHP. These functions enable you to easily access shared memory, much as you would access files. They don't use a proprietary segment header, meaning that the memory is easily shared between programs written in different languages. However, you must keep track of what's stored where; the shmop_*() functions don't provide the key=value functionality of the shm_*() functions.
The shmop_*() functions are not meant to be used in direct conjunction with the shm_*() functions, although you can access the same shared memory using either set of functions.
Some functions here accept values for permissions to be set on shared memory. Where this is the case, octal values are used, since octal is the standard notation for numeric permissions.
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.