Swoole\Lock->lockwait

4.x is outdated, please check the latest version 22.x


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Lock->lockwait ( int $timeout = 1 )

Parameters

timeout

Max waiting time to acquire the lock

Return

Description

Try to acquire the lock and waiting the lock for a duration before timeout.

Example

<?php

$lock = new Swoole\Lock(SWOOLE_MUTEX);
echo "[Master] Create lock\n";
$lock->lock();
if (pcntl_fork() > 0)
{
    sleep(1);
    $lock->unlock();
}
else
{
    echo "[Child] Wait Lock\n";
    $lock->lock();
    echo "[Child] Get Lock\n";
    $lock->unlock();
    exit("[Child] exit\n");
}
echo "[Master]release lock\n";
unset($lock);
sleep(1);
echo "[Master]exit\n";
Last updated on August 31, 2022