略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: SyncSharedMemory::__construct

2024-11-15

SyncSharedMemory::__construct

(PECL sync >= 1.1.0)

SyncSharedMemory::__constructConstructs a new SyncSharedMemory object

说明

public SyncSharedMemory::__construct(string $name, int $size)

Constructs a named shared memory object.

参数

name

The name of the shared memory 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.

size

The size, in bytes, of shared memory to reserve.

注意:

The amount of memory cannot be resized later. Request sufficient storage up front.

返回值

The new SyncSharedMemory object.

错误/异常

An exception is thrown if the shared memory object cannot be created or opened.

范例

示例 #1 SyncSharedMemory::__construct() example

<?php
// You will probably need to protect shared memory with other synchronization objects.
// Shared memory goes away when the last reference to it disappears.
$mem = new SyncSharedMemory("AppReportName"1024);
if (
$mem->first())
{
    
// Do first time initialization work here.
}

$result $mem->write(json_encode(array("name" => "my_report.txt")));
?>

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

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

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