Updated readme again
This commit is contained in:
parent
2652480c5d
commit
4e8ab73a88
61
README.md
61
README.md
@ -48,11 +48,12 @@ Traps are used in the main loop to break on signals
|
|||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
## Timers
|
### Timers
|
||||||
|
|
||||||
Timers fire asynchronously at fixed 1 second intervals. It requires signals to be
|
Timers fire asynchronously at fixed 1 second intervals. It requires signals to be
|
||||||
processed; see above.
|
processed; see above.
|
||||||
|
|
||||||
|
// Once every second...
|
||||||
$timer = new Timer(function () {
|
$timer = new Timer(function () {
|
||||||
echo ".";
|
echo ".";
|
||||||
});
|
});
|
||||||
@ -61,22 +62,64 @@ processed; see above.
|
|||||||
|
|
||||||
File locks uses a shared file as a resource for locking.
|
File locks uses a shared file as a resource for locking.
|
||||||
|
|
||||||
// Creating the lock will not acquire it
|
// Creating the lock will not acquire it
|
||||||
$lock = new FileLock(__FILE__);
|
$lock = new FileLock(__FILE__);
|
||||||
|
|
||||||
if (!$lock->acquire()) {
|
if (!$lock->acquire()) {
|
||||||
echo "fail!\n";
|
echo "fail!\n";
|
||||||
} else {
|
} else {
|
||||||
$lock->release();
|
$lock->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
## SysV wrappers
|
## SysV wrappers
|
||||||
|
|
||||||
|
All these wrappers depend on a `KeyInterface` being passed to the constructor.
|
||||||
|
This is usually an instance of a `FileKey`, created as such:
|
||||||
|
|
||||||
|
$key = new FileKey(__FILE__);
|
||||||
|
|
||||||
|
The key has a project identifier that starts at `chr(0)`, or `"\0"`. To increase
|
||||||
|
this identifier, and thus point to another segment, just clone it.
|
||||||
|
|
||||||
|
$key2 = clone $key1;
|
||||||
|
|
||||||
### Semaphores
|
### Semaphores
|
||||||
|
|
||||||
### Mutexes
|
### Mutexes
|
||||||
|
|
||||||
### Messagae Queues
|
### Message Queues
|
||||||
|
|
||||||
|
$key = new FileKey(__FILE__);
|
||||||
|
$msgq = new Queue($key);
|
||||||
|
|
||||||
|
$msgq->send(1, [ "Some data", [ "format"=>"foo" ]]);
|
||||||
|
|
||||||
|
$data = $msgq->receive(1, $type);
|
||||||
|
|
||||||
|
$msgq->destroy();
|
||||||
|
|
||||||
|
### Shared Memory
|
||||||
|
|
||||||
|
Shared memory using `SharedData` supports integrity checking when setting, using
|
||||||
|
the third parameter to `set()`.
|
||||||
|
|
||||||
|
$key = new FileKey(__FILE__);
|
||||||
|
$shm = new SharedData($key);
|
||||||
|
|
||||||
|
do {
|
||||||
|
$counter = $shm->get("counter") + 1;
|
||||||
|
} while (!$shm->set("counter", $counter, true));
|
||||||
|
|
||||||
|
$shm->destroy();
|
||||||
|
|
||||||
|
The `SharedMemory` class is a simple integer-indexed array
|
||||||
|
|
||||||
|
$key = new FileKey(__FILE__);
|
||||||
|
$shm = new SharedMemory($key);
|
||||||
|
|
||||||
|
$shm[0] = 42;
|
||||||
|
|
||||||
|
$shm->destroy();
|
||||||
|
|
||||||
## Communication
|
## Communication
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user