略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: SyncMutex::__construct

2024-11-13

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 noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/syncmutex.construct.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3