php8.5
Home/ Manual/ sync / syncsharedmemory/ SyncSharedMemory::__construct

SyncSharedMemory::__construct

PHP function Edit on GitHub ✎

(PECL sync >= 1.1.0)

Constructs a new SyncSharedMemory object

Description

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

Constructs a named shared memory object.

Parameters

name

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

size

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

Note

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

Return Values

The new SyncSharedMemory object.

Errors/Exceptions

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

Examples

SyncSharedMemory::__construct() example

php
<?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")));
?>

See Also

  • SyncSharedMemory::first
  • SyncSharedMemory::size
  • SyncSharedMemory::write
  • SyncSharedMemory::read

Source: reference/sync/syncsharedmemory/construct.xml · from the official PHP manual (php/doc-en)