发布于 2015-08-09 09:33:29 | 489 次阅读 | 评论: 0 | 来源: 网络整理
swoole1.6.4版本增加了锁的实现。PHP代码中可以很方便地创建一个锁,用来实现数据同步。swoole_lock类支持5种锁的类型:
$lock = new swoole_lock(SWOOLE_MUTEX);
echo "[Master]create lockn";
$lock->lock();
if(pcntl_fork() > 0)
{
sleep(1);
$lock->unlock();
}
else
{
echo "[Child] Wait Lockn";
$lock->lock();
echo "[Child] Get Lockn";
$lock->unlock();
exit("[Child] exitn");
}
echo "[Master]release lockn";
unset($lock);
sleep(1);
echo "[Master]exitn";
swoole_lock->__construct |
swoole_lock->lock |
swoole_lock->trylock |
swoole_lock->unlock |
swoole_lock->lock_read |
swoole_lock->trylock_read |