PHP 8.4.2 Released!

SyncMutex::__construct

(PECL sync >= 1.0.0)

SyncMutex::__constructConstructs a new SyncMutex object

Опис

public SyncMutex::__construct(string $name = ?)

Constructs a named or unnamed countable mutex.

Параметри

name

The name of the mutex if this is a named mutex object.

Зауваження:

If the name already exists, it must be able to be opened by the current user that the process is running as or an exception will be thrown with a meaningless error message.

Значення, що повертаються

The new SyncMutex object.

Помилки/виключення

An exception is thrown if the mutex cannot be created or opened.

Приклади

Приклад #1 SyncMutex::__construct() named mutex with lock timeout example

<?php
$mutex
= new SyncMutex("UniqueName");

if (!
$mutex->lock(3000))
{
echo
"Unable to lock mutex.";

exit();
}

/* ... */

$mutex->unlock();
?>

Приклад #2 SyncMutex::__construct() unnamed mutex example

<?php
$mutex
= new SyncMutex();

$mutex->lock();

/* ... */

$mutex->unlock();
?>

Прогляньте також

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top