Updated readme again
This commit is contained in:
		
							
								
								
									
										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
 | 
			
		||||
processed; see above.
 | 
			
		||||
 | 
			
		||||
    // Once every second...
 | 
			
		||||
    $timer = new Timer(function () {
 | 
			
		||||
        echo ".";
 | 
			
		||||
    });
 | 
			
		||||
@@ -61,22 +62,64 @@ processed; see above.
 | 
			
		||||
 | 
			
		||||
File locks uses a shared file as a resource for locking.
 | 
			
		||||
 | 
			
		||||
// Creating the lock will not acquire it
 | 
			
		||||
$lock = new FileLock(__FILE__);
 | 
			
		||||
    // Creating the lock will not acquire it
 | 
			
		||||
    $lock = new FileLock(__FILE__);
 | 
			
		||||
 | 
			
		||||
if (!$lock->acquire()) {
 | 
			
		||||
    echo "fail!\n";
 | 
			
		||||
} else {
 | 
			
		||||
    $lock->release();
 | 
			
		||||
}
 | 
			
		||||
    if (!$lock->acquire()) {
 | 
			
		||||
        echo "fail!\n";
 | 
			
		||||
    } else {
 | 
			
		||||
        $lock->release();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
## 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
 | 
			
		||||
 | 
			
		||||
### 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
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user