首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

SyncSharedMemory::__construct

(PECL sync >= 1.1.0)

SyncSharedMemory::__construct — Constructs a new SyncSharedMemory object

Description

代码语言:javascript
复制
public SyncSharedMemory::__construct ( string $name , integer $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. An exception is thrown if the shared memory object cannot be created or opened.

Examples

Example #1 SyncSharedMemory::__construct() example

代码语言:javascript
复制
<?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() - Check to see if the object is the first instance system-wide of named shared memory
  • SyncSharedMemory::size() - Returns the size of the named shared memory
  • SyncSharedMemory::write() - Copy data to named shared memory

← SyncSharedMemory

SyncSharedMemory::first →

代码语言:txt
复制
 ? 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com