The extension offers a set of operations to store an integer value in the shared memory, associated with a name (string identifier). Each value is to be atomically changed.
Supported versions of PHP: 7.0+, 8.0+
The extension appeared as during tackling with Lock Contention in APCu.
It allocates a number of segments in shared memory, each segment gets its own lock to perform the operation.
Each value may have its own TTL or live forever
Assuming that PHP is already installed on the system
git clone git@github.com:bumble-tech/php-sic.git
cd php-sic
phpize
./configure
make
make test
INI records related to the extension
# Attach the extension in the runtime
extension=sic.so
; Enable/disable the extension
;
; for the moment, it can only be set in PHP_INI_SYSTEM
;
; Boolean: 1/0/on/off/true/false
; Default Value: off
sic.enabled = on
; The number of "segments" to create on startup
;
; Integer: should be > 0
; Default Value: 10
sic.shard_num = 10
; The segment size
;
; Memory: 1M/100K/etc...
; Default Value: 1M
sic.shard_size=200K
Forcibly sets the value
key string, the key associated with the value
value int, the new value to set
ttl int, time to live in seconds
true on success, false otherwise
Creates a value in the storage. Fails if a value with such a name already exists.
key string, the key associated with the value
value int, the new value to set
ttl int, time to live in seconds
true on success, false otherwise
Removes the value from the storage. Fails if the value doesn't exists.
key string, the key associated with the value\
true on success, false otherwise
Retreives the value from the storage
key string, the key associated with the value
false if error occured or the value does not exists, int - the value, otherwise
Checks whether the value exists in the storage
key string, the key associated with the value
false if error occured or the value does not exists, true otherwise
Increments the value, fails if such a key does not exist
key string, the key associated with the value
value int, value of increment
ttl int, time to live in seconds
false if error occured or the value does not exists, int - the new value otherwise
Increments the value, fails if such a key does not exist
key string, the key associated with the value
value int, value of decrement
ttl int, time to live in seconds
false if error occured or the value does not exists, int - the new value otherwise
Updates the value using Compare-And-Swap semantic. Updates the value if the current value is expected (== old_value)
key string, the key associated with the value
old_value int, expected value
new_value int, the new value to set
false if error occured or the value does not exists, int - the new value otherwise
Runs Garbadge Collection
false if error occured
Returns info about segments, an element for each segment:
size int the size of the segment in bytes
unused_size int how much memory is not used yet in the segment, bytes
used_cnt int number of stored items
used_data_size int how much memory is used, bytes
frag_err_cnt int
oom_err_cnt int
In case API of the extension needs to be modified it should be done via editing sic.stub.php (do not edit any _arginfo* files as they are autogenerated) and calling https://github.com/php/php-src/blob/master/build/gen_stub.php afterwards. For more information please see