ftok

Convert a pathname and a project identifier to a System V IPC key

说明

int ftok ( string $pathname , string $proj )

The function converts the pathname of an existing accessible file and a project identifier into an integer for use with for example shmop_open and other System V IPC keys.

参数

pathname
Path to an accessible file.

proj
Project identifier. This must be a one character string.

返回值

On success the return value will be the created key value, otherwise -1 is returned.

参见

  • shmop_open
  • sem_get

msg_get_queue

Create or attach to a message queue

说明

resource msg_get_queue ( int $key [, int $perms = 0666 ] )

msg_get_queue returns an id that can be used to access the System V message queue with the given key. The first call creates the message queue with the optional perms. A second call to msg_get_queue for the same key will return a different message queue identifier, but both identifiers access the same underlying message queue.

参数

key
Message queue numeric ID

perms
Queue permissions. Default to 0666. If the message queue already exists, the perms will be ignored.

返回值

Returns a resource handle that can be used to access the System V message queue.

参见

  • msg_remove_queue
  • msg_receive
  • msg_send
  • msg_stat_queue
  • msg_set_queue

msg_queue_exists

Check whether a message queue exists

说明

bool msg_queue_exists ( int $key )

Checks whether the message queue key exists.

参数

key
Queue key.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • msg_remove_queue
  • msg_receive
  • msg_stat_queue

msg_receive

Receive a message from a message queue

说明

bool msg_receive ( resource $queue , int $desiredmsgtype , int &$msgtype , int $maxsize , mixed &$message [, bool $unserialize = TRUE [, int $flags = 0 [, int &$errorcode ]]] )

msg_receive will receive the first message from the specified queue of the type specified by desiredmsgtype.

参数

queue
Message queue resource handle

desiredmsgtype
If desiredmsgtype is 0, the message from the front of the queue is returned. If desiredmsgtype is greater than 0, then the first message of that type is returned. If desiredmsgtype is less than 0, the first message on the queue with a type less than or equal to the absolute value of desiredmsgtype will be read. If no messages match the criteria, your script will wait until a suitable message arrives on the queue. You can prevent the script from blocking by specifying MSG_IPC_NOWAIT in the flags parameter.

msgtype
The type of the message that was received will be stored in this parameter.

maxsize
The maximum size of message to be accepted is specified by the maxsize; if the message in the queue is larger than this size the function will fail (unless you set flags as described below).

message
The received message will be stored in message, unless there were errors receiving the message.

unserialize
If set to TRUE, the message is treated as though it was serialized using the same mechanism as the session module. The message will be unserialized and then returned to your script. This allows you to easily receive arrays or complex object structures from other PHP scripts, or if you are using the WDDX serializer, from any WDDX compatible source.

If unserialize is FALSE, the message will be returned as a binary-safe string.

flags
The optional flags allows you to pass flags to the low-level msgrcv system call. It defaults to 0, but you may specify one or more of the following values (by adding or ORing them together).

MSG_IPC_NOWAITIf there are no messages of the desiredmsgtype, return immediately and do not wait. The function will fail and return an integer value corresponding to MSG_ENOMSG.
MSG_EXCEPTUsing this flag in combination with a desiredmsgtype greater than 0 will cause the function to receive the first message that is not equal to desiredmsgtype.
MSG_NOERRORIf the message is longer than maxsize, setting this flag will truncate the message to maxsize and will not signal an error.

errorcode
If the function fails, the optional errorcode will be set to the value of the system errno variable.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

Upon successful completion the message queue data structure is updated as follows: msg_lrpid is set to the process-ID of the calling process, msg_qnum is decremented by 1 and msg_rtime is set to the current time.

参见

  • msg_remove_queue
  • msg_send
  • msg_stat_queue
  • msg_set_queue

msg_remove_queue

Destroy a message queue

说明

bool msg_remove_queue ( resource $queue )

msg_remove_queue destroys the message queue specified by the queue. Only use this function when all processes have finished working with the message queue and you need to release the system resources held by it.

参数

queue
Message queue resource handle

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • msg_get_queue
  • msg_receive
  • msg_stat_queue
  • msg_set_queue

msg_send

Send a message to a message queue

说明

bool msg_send ( resource $queue , int $msgtype , mixed $message [, bool $serialize = TRUE [, bool $blocking = TRUE [, int &$errorcode ]]] )

msg_send sends a message of type msgtype (which MUST be greater than 0) to the message queue specified by queue.

参数

queue
Message queue resource handle

msgtype
The type of the message (MUST be greater than 0)

message
The body of the message.

Note:

If serialize set to FALSE is supplied, MUST be of type: class="type">string, integer, class="type">float or bool. In other case a warning will be issued.

serialize
The optional serialize controls how the message is sent. serialize defaults to TRUE which means that the message is serialized using the same mechanism as the session module before being sent to the queue. This allows complex arrays and objects to be sent to other PHP scripts, or if you are using the WDDX serializer, to any WDDX compatible client.

blocking
If the message is too large to fit in the queue, your script will wait until another process reads messages from the queue and frees enough space for your message to be sent. This is called blocking; you can prevent blocking by setting the optional blocking parameter to FALSE, in which case msg_send will immediately return FALSE if the message is too big for the queue, and set the optional errorcode to MSG_EAGAIN, indicating that you should try to send your message again a little later on.

errorcode
If the function fails, the optional errorcode will be set to the value of the system errno variable.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

Upon successful completion the message queue data structure is updated as follows: msg_lspid is set to the process-ID of the calling process, msg_qnum is incremented by 1 and msg_stime is set to the current time.

参见

  • msg_remove_queue
  • msg_receive
  • msg_stat_queue
  • msg_set_queue

msg_set_queue

Set information in the message queue data structure

说明

bool msg_set_queue ( resource $queue , array $data )

msg_set_queue allows you to change the values of the msg_perm.uid, msg_perm.gid, msg_perm.mode and msg_qbytes fields of the underlying message queue data structure.

Changing the data structure will require that PHP be running as the same user that created the queue, owns the queue (as determined by the existing msg_perm.xxx fields), or be running with root privileges. root privileges are required to raise the msg_qbytes values above the system defined limit.

参数

queue
Message queue resource handle

data
You specify the values you require by setting the value of the keys that you require in the data array.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • msg_remove_queue
  • msg_receive
  • msg_stat_queue
  • msg_get_queue

msg_stat_queue

Returns information from the message queue data structure

说明

array msg_stat_queue ( resource $queue )

msg_stat_queue returns the message queue meta data for the message queue specified by the queue. This is useful, for example, to determine which process sent the message that was just received.

参数

queue
Message queue resource handle

返回值

The return value is an array whose keys and values have the following meanings:

msg_perm.uidThe uid of the owner of the queue.
msg_perm.gidThe gid of the owner of the queue.
msg_perm.modeThe file access mode of the queue.
msg_stimeThe time that the last message was sent to the queue.
msg_rtimeThe time that the last message was received from the queue.
msg_ctimeThe time that the queue was last changed.
msg_qnumThe number of messages waiting to be read from the queue.
msg_qbytesThe maximum number of bytes allowed in one message queue. On Linux, this value may be read and modified via /proc/sys/kernel/msgmnb.
msg_lspidThe pid of the process that sent the last message to the queue.
msg_lrpidThe pid of the process that received the last message from the queue.

参见

  • msg_remove_queue
  • msg_receive
  • msg_get_queue
  • msg_set_queue

sem_acquire

Acquire a semaphore

说明

bool sem_acquire ( resource $sem_identifier [, bool $nowait = FALSE ] )

sem_acquire by default blocks (if necessary) until the semaphore can be acquired. A process attempting to acquire a semaphore which it has already acquired will block forever if acquiring the semaphore would cause its maximum number of semaphore to be exceeded.

After processing a request, any semaphores acquired by the process but not explicitly released will be released automatically and a warning will be generated.

参数

sem_identifier
sem_identifier is a semaphore resource, obtained from sem_get.

nowait
Specifies if the process shouldn't wait for the semaphore to be acquired. If set to true, the call will return false immediately if a semaphore cannot be immediately acquired.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

更新日志

版本说明
5.6.1The $nowait parameter was added.

参见

  • sem_get
  • sem_release

sem_get

Get a semaphore id

说明

resource sem_get ( int $key [, int $max_acquire = 1 [, int $perm = 0666 [, int $auto_release = 1 ]]] )

sem_get returns an id that can be used to access the System V semaphore with the given key.

A second call to sem_get for the same key will return a different semaphore identifier, but both identifiers access the same underlying semaphore.

If key is 0, a new private semaphore is created for each call to sem_get.

参数

key

max_acquire
The number of processes that can acquire the semaphore simultaneously is set to max_acquire.

perm
The semaphore permissions. Actually this value is set only if the process finds it is the only process currently attached to the semaphore.

auto_release
Specifies if the semaphore should be automatically released on request shutdown.

返回值

Returns a positive semaphore identifier on success, or FALSE on error.

注释

Warning

When using sem_get to access a semaphore created outside PHP, note that the semaphore must have been created as a set of 3 semaphores (for example, by specifying 3 as the nsems parameter when calling the C semget() function), otherwise PHP will be unable to access the semaphore.

参见

  • sem_acquire
  • sem_release
  • ftok

sem_release

Release a semaphore

说明

bool sem_release ( resource $sem_identifier )

sem_release releases the semaphore if it is currently acquired by the calling process, otherwise a warning is generated.

After releasing the semaphore, sem_acquire may be called to re-acquire it.

参数

sem_identifier
A Semaphore resource handle as returned by sem_get.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • sem_get
  • sem_acquire

sem_remove

Remove a semaphore

说明

bool sem_remove ( resource $sem_identifier )

sem_remove removes the given semaphore.

After removing the semaphore, it is no longer accessible.

参数

sem_identifier
A semaphore resource identifier as returned by sem_get.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • sem_get
  • sem_release
  • sem_acquire

shm_attach

Creates or open a shared memory segment

说明

resource shm_attach ( int $key [, int $memsize [, int $perm = 0666 ]] )

shm_attach returns an id that can be used to access the System V shared memory with the given key, the first call creates the shared memory segment with memsize and the optional perm-bits perm.

A second call to shm_attach for the same key will return a different shared memory identifier, but both identifiers access the same underlying shared memory. memsize and perm will be ignored.

参数

key
A numeric shared memory segment ID

memsize
The memory size. If not provided, default to the sysvshm.init_mem in the php.ini, otherwise 10000 bytes.

perm
The optional permission bits. Default to 0666.

返回值

Returns a shared memory segment identifier.

更新日志

版本说明
5.3.0This function now returns a 资源(resource) instead of an integer.

注释

Note:

This function used to return an integer value prior to PHP 5.3.0. To achieve the same value in a portable manner, the return value can be cast to an integer like:

<?php
// Create a temporary file and return its path
$tmp = tempnam('/tmp', 'PHP');

// Get the file token key
$key = ftok($tmp, 'a');

// Attach the SHM resource, notice the cast afterwards
$id = shm_attach($key);

if ($id === false) {
    die('Unable to create the shared memory segment');
}

// Cast to integer, since prior to PHP 5.3.0 the resource id 
// is returned which can be exposed when casting a resource
// to an integer
$id = (integer) $id;
?>

参见

  • shm_detach
  • ftok

shm_detach

Disconnects from shared memory segment

说明

bool shm_detach ( resource $shm_identifier )

shm_detach disconnects from the shared memory given by the shm_identifier created by shm_attach. Remember, that shared memory still exist in the Unix system and the data is still present.

参数

shm_identifier
A shared memory resource handle as returned by shm_attach

返回值

shm_detach always returns TRUE.

参见

  • shm_attach
  • shm_remove
  • shm_remove_var

shm_get_var

Returns a variable from shared memory

说明

mixed shm_get_var ( resource $shm_identifier , int $variable_key )

shm_get_var returns the variable with a given variable_key, in the given shared memory segment. The variable is still present in the shared memory.

参数

shm_identifier
Shared memory segment, obtained from shm_attach.

variable_key
The variable key.

返回值

Returns the variable with the given key.

参见

  • shm_has_var
  • shm_put_var

shm_has_var

Check whether a specific entry exists

说明

bool shm_has_var ( resource $shm_identifier , int $variable_key )

Checks whether a specific key exists inside a shared memory segment.

参数

shm_identifier
Shared memory segment, obtained from shm_attach.

variable_key
The variable key.

返回值

Returns TRUE if the entry exists, otherwise FALSE

参见

  • shm_get_var
  • shm_put_var

shm_put_var

Inserts or updates a variable in shared memory

说明

bool shm_put_var ( resource $shm_identifier , int $variable_key , mixed $variable )

shm_put_var inserts or updates the variable with the given variable_key.

Warnings (E_WARNING level) will be issued if shm_identifier is not a valid SysV shared memory index or if there was not enough shared memory remaining to complete your request.

参数

shm_identifier
A shared memory resource handle as returned by shm_attach

variable_key
The variable key.

variable
The variable. All variable types that serialize supports may be used: generally this means all types except for resources and some internal objects that cannot be serialized.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • shm_get_var
  • shm_has_var

shm_remove_var

Removes a variable from shared memory

说明

bool shm_remove_var ( resource $shm_identifier , int $variable_key )

Removes a variable with a given variable_key and frees the occupied memory.

参数

shm_identifier
The shared memory identifier as returned by shm_attach

variable_key
The variable key.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • shm_remove

shm_remove

Removes shared memory from Unix systems

说明

bool shm_remove ( resource $shm_identifier )

shm_remove removes the shared memory shm_identifier. All data will be destroyed.

参数

shm_identifier
The shared memory identifier as returned by shm_attach

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • shm_remove_var

目录