(PECL sync >= 1.0.0)
SyncMutex::__construct — Constructs a new SyncMutex object
Constructs a named or unnamed countable mutex.
name
The name of the mutex if this is a named mutex object.
Note:
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.
Example #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();
?>
Example #2 SyncMutex::__construct() unnamed mutex example
<?php
$mutex = new SyncMutex();
$mutex->lock();
/* ... */
$mutex->unlock();
?>
Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!
Check out: eBank.nz (Art Generator) |
Netwrck.com (AI Tools) |
Text-Generator.io (AI API) |
BitBank.nz (Crypto AI) |
ReadingTime (Kids Reading) |
RewordGame |
BigMultiplayerChess |
WebFiddle |
How.nz |
Helix AI Assistant