2002-01-09 16:02:21 +08:00
|
|
|
last update Jan 2, 2002 (hackie@prohost.org/ilia@prohost.org)
|
2000-10-01 23:06:04 +08:00
|
|
|
|
2004-01-17 21:00:38 +08:00
|
|
|
Shared Memory Operations Extension to PHP
|
2000-10-01 23:06:04 +08:00
|
|
|
|
2002-01-09 16:02:21 +08:00
|
|
|
While developing a search deamon we needed a php based front end
|
|
|
|
to communicate the deamon via SHM. PHP already had a shared memory
|
2000-10-01 23:06:04 +08:00
|
|
|
extention (sysvshm) written by Christian Cartus <cartus@atrior.de>,
|
2002-01-09 16:02:21 +08:00
|
|
|
unfortunatly this extention was designed with PHP only in mind and
|
2000-10-01 23:06:04 +08:00
|
|
|
offers high level features which are extremly bothersome for basic SHM
|
2002-01-09 16:02:21 +08:00
|
|
|
we had in mind. After spending a day trying to reverse engineer and figure
|
2000-10-01 23:06:04 +08:00
|
|
|
out the format of sysvshm we decided that it would be much easier to
|
|
|
|
add our own extention to php for simple SHM operations, we were right :)).
|
|
|
|
|
|
|
|
the functions are:
|
|
|
|
|
2002-01-09 16:02:21 +08:00
|
|
|
int shmop_open(int key, string flags, int mode, int size)
|
2000-10-01 23:06:04 +08:00
|
|
|
|
|
|
|
key - the key of/for the shared memory block
|
2002-01-09 16:02:21 +08:00
|
|
|
flags - 4 flags are avalible
|
|
|
|
a for read only access (sets SHM_RDONLY)
|
|
|
|
w for read & write access
|
|
|
|
c create or open an existing segment (sets IPC_CREATE)
|
|
|
|
n create a new segment and fail if one already exists under same name (sets IPC_CREATE|IPC_EXCL)
|
|
|
|
(the n flag is mostly useful for security perpouses, so that you don't end up opening a faked segment
|
|
|
|
if someone guesses your key)
|
2000-10-01 23:06:04 +08:00
|
|
|
mode - acsess mode same as for a file (0644) for example
|
|
|
|
size - size of the block in bytes
|
|
|
|
|
|
|
|
returns an indentifier
|
|
|
|
|
|
|
|
|
2002-01-09 16:02:21 +08:00
|
|
|
char shmop_read(int shmid, int start, int count)
|
2000-10-01 23:06:04 +08:00
|
|
|
|
|
|
|
shmid - shmid from which to read
|
|
|
|
start - offset from which to start reading
|
|
|
|
count - how many bytes to read
|
|
|
|
|
|
|
|
returns the data read
|
|
|
|
|
2002-01-09 16:02:21 +08:00
|
|
|
int shmop_write(int shmid, string data, int offset)
|
2000-10-01 23:06:04 +08:00
|
|
|
|
|
|
|
shmid - shmid from which to read
|
|
|
|
data - string to put into shared memory
|
|
|
|
offset - offset in shm to write from
|
|
|
|
|
|
|
|
returns bytes written
|
|
|
|
|
2002-01-09 16:02:21 +08:00
|
|
|
int shmop_size(int shmid)
|
2000-10-01 23:06:04 +08:00
|
|
|
|
|
|
|
shmid - shmid for which to return the size
|
|
|
|
|
|
|
|
returns the size in bytes of the shm segment
|
|
|
|
|
|
|
|
|
2002-01-09 16:02:21 +08:00
|
|
|
int shmop_delete(int shmid)
|
2000-10-01 23:06:04 +08:00
|
|
|
|
|
|
|
marks the segment for deletion, the segment will be deleted when all processes mapping it will detach
|
|
|
|
|
|
|
|
shmid - shmid which to mark for deletion
|
|
|
|
|
|
|
|
returns 1 if all ok, zero on failure
|
|
|
|
|
2002-01-09 16:02:21 +08:00
|
|
|
int shmop_close(int shmid)
|
2000-10-01 23:06:04 +08:00
|
|
|
|
|
|
|
shmid - shmid which to close
|
|
|
|
|
|
|
|
returns zero
|
|
|
|
|
|
|
|
|