| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\ShmopException; |
| 6 |
|
| 7 |
/** |
| 8 |
* shmop_delete is used to delete a shared memory block. |
| 9 |
* |
| 10 |
* @param resource $shmid The shared memory block resource created by |
| 11 |
* shmop_open |
| 12 |
* @throws ShmopException |
| 13 |
* |
| 14 |
*/ |
| 15 |
function shmop_delete($shmid): void |
| 16 |
{ |
| 17 |
error_clear_last(); |
| 18 |
$result = \shmop_delete($shmid); |
| 19 |
if ($result === false) { |
| 20 |
throw ShmopException::createFromPhpError(); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
/** |
| 26 |
* shmop_read will read a string from shared memory block. |
| 27 |
* |
| 28 |
* @param resource $shmid The shared memory block identifier created by |
| 29 |
* shmop_open |
| 30 |
* @param int $start Offset from which to start reading |
| 31 |
* @param int $count The number of bytes to read. |
| 32 |
* 0 reads shmop_size($shmid) - $start bytes. |
| 33 |
* @return string Returns the data. |
| 34 |
* @throws ShmopException |
| 35 |
* |
| 36 |
*/ |
| 37 |
function shmop_read($shmid, int $start, int $count): string |
| 38 |
{ |
| 39 |
error_clear_last(); |
| 40 |
$result = \shmop_read($shmid, $start, $count); |
| 41 |
if ($result === false) { |
| 42 |
throw ShmopException::createFromPhpError(); |
| 43 |
} |
| 44 |
return $result; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
/** |
| 49 |
* shmop_write will write a string into shared memory block. |
| 50 |
* |
| 51 |
* @param resource $shmid The shared memory block identifier created by |
| 52 |
* shmop_open |
| 53 |
* @param string $data A string to write into shared memory block |
| 54 |
* @param int $offset Specifies where to start writing data inside the shared memory |
| 55 |
* segment. |
| 56 |
* @return int The size of the written data. |
| 57 |
* @throws ShmopException |
| 58 |
* |
| 59 |
*/ |
| 60 |
function shmop_write($shmid, string $data, int $offset): int |
| 61 |
{ |
| 62 |
error_clear_last(); |
| 63 |
$result = \shmop_write($shmid, $data, $offset); |
| 64 |
if ($result === false) { |
| 65 |
throw ShmopException::createFromPhpError(); |
| 66 |
} |
| 67 |
return $result; |
| 68 |
} |
| 69 |
|