Ref/sem-Phpdoc专题

ftok

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

说明

int ftok ( string $filename , <span class="type">string $project_id )

The function converts the filename of an existing accessible file and a project identifier into an integer for use with for example <span class="function">shmop_open and other System V IPC keys.

参数

filename
Path to an accessible file.

project_id
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

说明

SysvMessageQueue<span class="type">false <span class="methodname">msg_get_queue ( <span class="methodparam">int $key [, int $permissions = 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 permissions. 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

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

返回值

Returns SysvMessageQueue instance that can be used to access the System V message queue, 或者在失败时返回 false.

更新日志

版本 说明
8.0.0 On success, this function returns a SysvMessageQueue instance now; previously, a resource was returned.

参见

  • msg_remove_queue
  • msg_receive
  • msg_send
  • msg_stat_queue
  • msg_set_queue

msg_queue_exists

Check whether a message queue exists

说明

bool <span class="methodname">msg_queue_exists ( <span class="methodparam">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 <span class="methodname">msg_receive ( <span class="type">SysvMessageQueue $queue , <span class="methodparam">int $desired_message_type , <span class="type">int &$received_message_type , <span class="methodparam">int $max_message_size , <span class="type">mixed &$message [, <span class="methodparam">bool $unserialize<span class="initializer"> = true [, <span class="methodparam">int $flags<span class="initializer"> = 0 [, <span class="methodparam">int &$error_code<span class="initializer"> = null ]]] )

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

参数

queue
The message queue.

desired_message_type
If desired_message_type is 0, the message from the front of the queue is returned. If desired_message_type is greater than 0, then the first message of that type is returned. If desired_message_type is less than 0, the first message on the queue with a type less than or equal to the absolute value of desired_message_type 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.

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

max_message_size
The maximum size of message to be accepted is specified by the max_message_size; 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_NOWAIT If there are no messages of the desired_message_type, return immediately and do not wait. The function will fail and return an integer value corresponding to MSG_ENOMSG.
MSG_EXCEPT Using this flag in combination with a desired_message_type greater than 0 will cause the function to receive the first message that is not equal to desired_message_type.
MSG_NOERROR If the message is longer than max_message_size, setting this flag will truncate the message to max_message_size and will not signal an error.

error_code
If the function fails, the optional error_code 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.

更新日志

版本 说明
8.0.0 queue expects a SysvMessageQueue instance now; previously, a resource was expected.

参见

  • msg_remove_queue
  • msg_send
  • msg_stat_queue
  • msg_set_queue

msg_remove_queue

Destroy a message queue

说明

bool <span class="methodname">msg_remove_queue ( <span class="methodparam">SysvMessageQueue $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
The message queue.

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.0.0 queue expects a SysvMessageQueue instance now; previously, a resource was expected.

参见

  • msg_get_queue
  • msg_receive
  • msg_stat_queue
  • msg_set_queue

msg_send

Send a message to a message queue

说明

bool msg_send ( SysvMessageQueue $queue , <span class="type">int $message_type , <span class="methodparam"><span class="type">stringint<span class="type">floatbool $message [, <span class="type">bool $serialize = true [, <span class="type">bool $blocking = true [, <span class="type">int &$error_code = null ]]] )

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

参数

queue
The message queue.

message_type
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: <span class="type">string, int, <span 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 error_code to MSG_EAGAIN, indicating that you should try to send your message again a little later on.

error_code
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.

更新日志

版本 说明
8.0.0 queue expects a SysvMessageQueue instance now; previously, a resource was expected.

参见

  • msg_remove_queue
  • msg_receive
  • msg_stat_queue
  • msg_set_queue

msg_set_queue

Set information in the message queue data structure

说明

bool <span class="methodname">msg_set_queue ( <span class="methodparam">SysvMessageQueue $queue , <span class="type">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
The message queue.

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

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.0.0 queue expects a SysvMessageQueue instance now; previously, a resource was expected.

参见

  • msg_remove_queue
  • msg_receive
  • msg_stat_queue
  • msg_get_queue

msg_stat_queue

Returns information from the message queue data structure

说明

array<span class="type">false <span class="methodname">msg_stat_queue ( <span class="methodparam">SysvMessageQueue $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
The message queue.

返回值

On success, the return value is an array whose keys and values have the following meanings:

msg_perm.uid The uid of the owner of the queue.
msg_perm.gid The gid of the owner of the queue.
msg_perm.mode The file access mode of the queue.
msg_stime The time that the last message was sent to the queue.
msg_rtime The time that the last message was received from the queue.
msg_ctime The time that the queue was last changed.
msg_qnum The number of messages waiting to be read from the queue.
msg_qbytes The maximum number of bytes allowed in one message queue. On Linux, this value may be read and modified via /proc/sys/kernel/msgmnb.
msg_lspid The pid of the process that sent the last message to the queue.
msg_lrpid The pid of the process that received the last message from the queue.

Returns false on failure.

更新日志

版本 说明
8.0.0 queue expects a SysvMessageQueue instance now; previously, a resource was expected.

参见

  • msg_remove_queue
  • msg_receive
  • msg_get_queue
  • msg_set_queue

sem_acquire

Acquire a semaphore

说明

bool <span class="methodname">sem_acquire ( <span class="type">SysvSemaphore $semaphore [, <span class="methodparam">bool $non_blocking<span class="initializer"> = 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.

参数

semaphore
semaphore is a semaphore obtained from <span class="function">sem_get.

non_blocking
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

更新日志

版本 说明
8.0.0 semaphore expects a SysvSemaphore instance now; previously, a resource was expected.

参见

  • sem_get
  • sem_release

sem_get

Get a semaphore id

说明

SysvSemaphore<span class="type">false <span class="methodname">sem_get ( <span class="type">int $key [, <span class="methodparam">int $max_acquire<span class="initializer"> = 1 [, <span class="methodparam">int $permissions<span class="initializer"> = 0666 [, <span class="methodparam">bool $auto_release<span class="initializer"> = true ]]] )

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.

permissions
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.

更新日志

版本 说明
8.0.0 On success, this function returns a SysvSemaphore instance now; previously, a resource was returned.
8.0.0 The type of auto_release has been changed from int to bool.

注释

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 <span class="methodname">sem_release ( <span class="type">SysvSemaphore $semaphore )

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

After releasing the semaphore, <span class="function">sem_acquire may be called to re-acquire it.

参数

semaphore
A Semaphore as returned by sem_get.

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.0.0 semaphore expects a SysvSemaphore instance now; previously, a resource was expected.

参见

  • sem_get
  • sem_acquire

sem_remove

Remove a semaphore

说明

bool <span class="methodname">sem_remove ( <span class="type">SysvSemaphore $semaphore )

sem_remove removes the given semaphore.

After removing the semaphore, it is no longer accessible.

参数

semaphore
A semaphore as returned by sem_get.

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.0.0 semaphore expects a SysvSemaphore instance now; previously, a resource was expected.

参见

  • sem_get
  • sem_release
  • sem_acquire

shm_attach

Creates or open a shared memory segment

说明

SysvSharedMemory<span class="type">false <span class="methodname">shm_attach ( <span class="type">int $key [, <span class="methodparam"><span class="type">intnull $size = null [, <span class="methodparam">int $permissions<span class="initializer"> = 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 size and the optional perm-bits permissions.

A second call to shm_attach for the same key will return a different <span class="classname">SysvSharedMemory instance, but both instances access the same underlying shared memory. size and permissions will be ignored.

参数

key
A numeric shared memory segment ID

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

permissions
The optional permission bits. Default to 0666.

返回值

Returns a SysvSharedMemory instance on success, 或者在失败时返回 false.

更新日志

版本 说明
8.0.0 On success, this function returns an SysvSharedMemory instance now; previously, a resource was returned.
8.0.0 size is nullable now.

参见

  • shm_detach
  • ftok

shm_detach

Disconnects from shared memory segment

说明

bool <span class="methodname">shm_detach ( <span class="type">SysvSharedMemory $shm )

shm_detach disconnects from the shared memory given by the shm created by <span class="function">shm_attach. Remember, that shared memory still exist in the Unix system and the data is still present.

参数

shm
A shared memory segment obtained from <span class="function">shm_attach.

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.0.0 shm expects a SysvSharedMemory instance now; previously, a resource was expected.

参见

  • shm_attach
  • shm_remove
  • shm_remove_var

shm_get_var

Returns a variable from shared memory

说明

mixed <span class="methodname">shm_get_var ( <span class="methodparam">SysvSharedMemory $shm , int $key )

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

参数

shm
A shared memory segment obtained from <span class="function">shm_attach.

key
The variable key.

返回值

Returns the variable with the given key.

更新日志

版本 说明
8.0.0 shm expects a SysvSharedMemory instance now; previously, a resource was expected.

参见

  • shm_has_var
  • shm_put_var

shm_has_var

Check whether a specific entry exists

说明

bool <span class="methodname">shm_has_var ( <span class="methodparam">SysvSharedMemory $shm , int $key )

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

参数

shm
A shared memory segment obtained from <span class="function">shm_attach.

key
The variable key.

返回值

Returns true if the entry exists, otherwise false

更新日志

版本 说明
8.0.0 shm expects a SysvSharedMemory instance now; previously, a resource was expected.

参见

  • shm_get_var
  • shm_put_var

shm_put_var

Inserts or updates a variable in shared memory

说明

bool <span class="methodname">shm_put_var ( <span class="methodparam">SysvSharedMemory $shm , int $key , <span class="type">mixed $value )

shm_put_var inserts or updates the value with the given key.

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

参数

shm
A shared memory segment obtained from <span class="function">shm_attach.

key
The variable key.

value
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

更新日志

版本 说明
8.0.0 shm expects a SysvSharedMemory instance now; previously, a resource was expected.

参见

  • shm_get_var
  • shm_has_var

shm_remove_var

Removes a variable from shared memory

说明

bool <span class="methodname">shm_remove_var ( <span class="methodparam">SysvSharedMemory $shm , int $key )

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

参数

shm
A shared memory segment obtained from <span class="function">shm_attach.

key
The variable key.

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.0.0 shm expects a SysvSharedMemory instance now; previously, a resource was expected.

参见

  • shm_remove

shm_remove

Removes shared memory from Unix systems

说明

bool <span class="methodname">shm_remove ( <span class="type">SysvSharedMemory $shm )

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

参数

shm
A shared memory segment obtained from <span class="function">shm_attach.

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.0.0 shm expects a SysvSharedMemory instance now; previously, a resource was expected.

参见

  • shm_remove_var

目录


本站为非盈利网站,作品由网友提供上传,如无意中有侵犯您的版权,请联系删除