OpenSwoole
ock->lock

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\Lock->lock()

Parameters

Return

Description

Try to acquire the lock. The process is blocking when the lock is not available.

Example

<?php

$lock = new OpenSwoole\Lock(OpenSwoole\Lock::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 September 20, 2022