2021-02-26 16:16:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Safe;
|
|
|
|
|
|
|
|
use Safe\Exceptions\ShmopException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* shmop_delete is used to delete a shared memory block.
|
|
|
|
*
|
2022-07-12 19:26:21 +00:00
|
|
|
* @param resource $shmop The shared memory block resource created by
|
2021-02-26 16:16:17 +00:00
|
|
|
* shmop_open
|
|
|
|
* @throws ShmopException
|
|
|
|
*
|
|
|
|
*/
|
2022-07-12 19:26:21 +00:00
|
|
|
function shmop_delete($shmop): void
|
2021-02-26 16:16:17 +00:00
|
|
|
{
|
|
|
|
error_clear_last();
|
2022-07-12 19:26:21 +00:00
|
|
|
$result = \shmop_delete($shmop);
|
2021-02-26 16:16:17 +00:00
|
|
|
if ($result === false) {
|
|
|
|
throw ShmopException::createFromPhpError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* shmop_read will read a string from shared memory block.
|
|
|
|
*
|
2022-07-12 19:26:21 +00:00
|
|
|
* @param resource $shmop The shared memory block identifier created by
|
2021-02-26 16:16:17 +00:00
|
|
|
* shmop_open
|
2022-07-12 19:26:21 +00:00
|
|
|
* @param int $offset Offset from which to start reading
|
|
|
|
* @param int $size The number of bytes to read.
|
2021-02-26 16:16:17 +00:00
|
|
|
* 0 reads shmop_size($shmid) - $start bytes.
|
|
|
|
* @return string Returns the data.
|
|
|
|
* @throws ShmopException
|
|
|
|
*
|
|
|
|
*/
|
2022-07-12 19:26:21 +00:00
|
|
|
function shmop_read($shmop, int $offset, int $size): string
|
2021-02-26 16:16:17 +00:00
|
|
|
{
|
|
|
|
error_clear_last();
|
2022-07-12 19:26:21 +00:00
|
|
|
$result = \shmop_read($shmop, $offset, $size);
|
2021-02-26 16:16:17 +00:00
|
|
|
if ($result === false) {
|
|
|
|
throw ShmopException::createFromPhpError();
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|