Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<Swoole\Coroutine\Lock::lockSwoole\Coroutine\Lock::unlock>
^Swoole\Coroutine\LockLast updated: Mon, 26 Oct 2026

Swoole\Coroutine\Lock::trylock

(No version information available, might only be in Git)

Swoole\Coroutine\Lock::trylock — Attempt to acquire the lock without blocking

Description

public function Swoole\Coroutine\Lock::trylock(): bool

When calling the lock operation, if the lock is already held by another coroutine, the function will immediately return false without suspending the current coroutine or yielding CPU control. This non-blocking design allows the caller to flexibly handle contention situations, such as retrying, giving up, or executing other logic.

Parameters

This function has no parameters.

Return Values

Returns true if the lock was acquired successfully, false if the lock is not available.


<Swoole\Coroutine\Lock::lockSwoole\Coroutine\Lock::unlock>
^Swoole\Coroutine\LockLast updated: Mon, 26 Oct 2026