PHP code example of sof3 / rwlock
1. Go to this page and download the library: Download sof3/rwlock library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sof3 / rwlock example snippets
$mutex = new Mutex;
$epoch = time();
yield $mutex->run(function() use($epoch) {
echo "Start 1: ", time() - $epoch, "\n";
yield $this->waitSeconds(2);
echo "End 1: ", time() - $epoch, "\n";
});
yield $mutex->run(function() use($epoch) {
echo "Start 2: ", time() - $epoch, "\n";
yield $this->waitSeconds(1);
echo "End 2: ", time() - $epoch, "\n";
});
$mutex = new RwLock;
$epoch = time();
Await::g2c($mutex->readClosure(function() use($epoch) {
echo "Start 1: ", time() - $epoch, "\n";
yield $this->waitSeconds(2);
echo "End 1: ", time() - $epoch, "\n";
}));
Await::g2c($mutex->readClosure(function() use($epoch, $mutex) {
echo "Start 2: ", time() - $epoch, "\n";
yield $this->waitSeconds(1);
echo "End 2: ", time() - $epoch, "\n";
Await::g2c($mutex->readClosure(function() use($epoch) {
echo "Start 3: ", time() - $epoch, "\n";
yield $this->waitSeconds(2);
echo "End 3: ", time() - $epoch, "\n";
}));
Await::f2c($mutex->writeClosure(function() use($epoch) {
echo "Start 4: ", time() - $epoch, "\n";
yield $this->waitSeconds(2);
echo "End 4: ", time() - $epoch, "\n";
}));
Await::f2c($mutex->readClosure(function() use($epoch) {
echo "Start 5: ", time() - $epoch, "\n";
yield $this->waitSeconds(2);
echo "End 5: ", time() - $epoch, "\n";
}));
}));