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

SyncSharedMemory::write

PHP function Edit on GitHub ✎

(PECL sync >= 1.1.0)

Copy data to named shared memory

Description

SyncSharedMemory::write([string $string], int $start = 0)

Copies data to named shared memory.

Parameters

string

The data to write to shared memory.

Note

If the size of the data exceeds the size of the shared memory, the number of bytes written returned will be less than the length of the input.

start

The start/offset, in bytes, to begin writing.

Note

If the value is negative, the starting position will begin at the specified number of bytes from the end of the shared memory segment.

Return Values

An integer containing the number of bytes written to shared memory.

Examples

SyncSharedMemory::write() 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("report.txt");
var_dump($result);

$result = $mem->write("report.txt", -3);
var_dump($result);
?>

The above example will output something similar to:

output
int(10)
int(3)

See Also

  • SyncSharedMemory::__construct
  • SyncSharedMemory::first
  • SyncSharedMemory::write
  • SyncSharedMemory::read

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