PHP 8.5.0 Beta 3 available for testing

SyncMutex::__construct

(PECL sync >= 1.0.0)

SyncMutex::__construct โ€” Constructs 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();
?>

ๅ‚่ง

๏ผ‹ๆทปๅŠ ๅค‡ๆณจ

็”จๆˆท่ดก็Œฎ็š„ๅค‡ๆณจ

ๆญค้กต้ขๅฐšๆ— ็”จๆˆท่ดก็Œฎ็š„ๅค‡ๆณจใ€‚
To Top