Skip to main content

PHP Shared Memory Debugger

July 9, 2002 by davidc

This utility allows you to see the contents of a shared memory segment created using the shm_* functions in PHP. Unlike the shmop functions, which allow you to read and write raw data in a shared memory segment, these are designed for PHP only and consist of serialized PHP variables in a linked list.

As there is no way to enumerate the values in a shared memory segment, this utility uses the shmop functions to read the segment raw, and then parses the data according to the sysvshm_chunk_head and sysvshm_chunk PHP-internal structures.

Usage

Usage: getshm [-v] <shmkey>
  -v       verbose information (byte pointers, etc)
  <shmkey> shared memory key passed to shm_attach()

-v gives you all the pointers and lengths from the raw shared memory segment.

Note you will need read access to the segment; the mode used to create the segment will affect your ability to read the segment if are not the user who created the segment.

Example

david@a6s:~# getshm 0x00120003
shm key 0x00120003 (1179651):
 
Variable:
  Key:         0
  Data:
    string(2) "aq"
 
Variable:
  Key:         1
  Data:
    int(201577)

david@a6s:~# getshm -v 0x00120003
shm key 0x00120003 (1179651):
segment size: 500
 
Header:
  Magic:       "PHP_SM"
  Data Start:  24
  Data End:    80
  Bytes Free:  420
  Bytes Total: 500
 
Variable:
  Key:         0
  Length:      9
  Next:        28
  Raw Data:    "s:2:"aq";"
  Unserialized data:
    string(2) "aq"
 
Variable:
  Key:         1
  Length:      9
  Next:        28
  Raw Data:    "i:201579;"
  Unserialized data:
    int(201579)

Compatibility

The sysvshm_ structures may change in a future version of PHP and cause this utility to break.

This is designed to read shm_* format segments only and will throw errors on other types of segment including raw shmop_* segments.

AttachmentSize
getshm.php (2004-05-13 14:23)2.05 KB