Exceptions
5 days ago
apache.php
5 days ago
apcu.php
5 days ago
array.php
5 days ago
bzip2.php
5 days ago
calendar.php
5 days ago
classobj.php
5 days ago
com.php
5 days ago
cubrid.php
5 days ago
curl.php
5 days ago
datetime.php
5 days ago
dir.php
5 days ago
eio.php
5 days ago
errorfunc.php
5 days ago
exec.php
5 days ago
fileinfo.php
5 days ago
filesystem.php
5 days ago
filter.php
5 days ago
fpm.php
5 days ago
ftp.php
5 days ago
funchand.php
5 days ago
functionsList.php
5 days ago
gmp.php
5 days ago
gnupg.php
5 days ago
hash.php
5 days ago
ibase.php
5 days ago
ibmDb2.php
5 days ago
iconv.php
5 days ago
image.php
5 days ago
imap.php
5 days ago
info.php
5 days ago
ingres-ii.php
5 days ago
inotify.php
5 days ago
json.php
5 days ago
ldap.php
5 days ago
libxml.php
5 days ago
lzf.php
5 days ago
mailparse.php
5 days ago
mbstring.php
5 days ago
misc.php
5 days ago
msql.php
5 days ago
mysql.php
5 days ago
mysqli.php
5 days ago
mysqlndMs.php
5 days ago
mysqlndQc.php
5 days ago
network.php
5 days ago
oci8.php
5 days ago
opcache.php
5 days ago
openssl.php
5 days ago
outcontrol.php
5 days ago
password.php
5 days ago
pcntl.php
5 days ago
pcre.php
5 days ago
pdf.php
5 days ago
pgsql.php
5 days ago
posix.php
5 days ago
ps.php
5 days ago
pspell.php
5 days ago
readline.php
5 days ago
rpminfo.php
5 days ago
rrd.php
5 days ago
sem.php
5 days ago
session.php
5 days ago
shmop.php
5 days ago
simplexml.php
5 days ago
sockets.php
5 days ago
sodium.php
5 days ago
solr.php
5 days ago
spl.php
5 days ago
sqlsrv.php
5 days ago
ssdeep.php
5 days ago
ssh2.php
5 days ago
stream.php
5 days ago
strings.php
5 days ago
swoole.php
5 days ago
uodbc.php
5 days ago
uopz.php
5 days ago
url.php
5 days ago
var.php
5 days ago
xdiff.php
5 days ago
xml.php
5 days ago
xmlrpc.php
5 days ago
yaml.php
5 days ago
yaz.php
5 days ago
zip.php
5 days ago
zlib.php
5 days ago
sem.php
345 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePressVendor\Safe; |
| 4 | |
| 5 | use ProfilePressVendor\Safe\Exceptions\SemException; |
| 6 | /** |
| 7 | * Checks whether the message queue key exists. |
| 8 | * |
| 9 | * @param int $key Queue key. |
| 10 | * @throws SemException |
| 11 | * |
| 12 | */ |
| 13 | function msg_queue_exists(int $key): void |
| 14 | { |
| 15 | error_clear_last(); |
| 16 | $result = \msg_queue_exists($key); |
| 17 | if ($result === \false) { |
| 18 | throw SemException::createFromPhpError(); |
| 19 | } |
| 20 | } |
| 21 | /** |
| 22 | * msg_receive will receive the first message from the |
| 23 | * specified queue of the type specified by |
| 24 | * desiredmsgtype. |
| 25 | * |
| 26 | * @param resource $queue Message queue resource handle |
| 27 | * @param int $desiredmsgtype If desiredmsgtype is 0, the message from the front |
| 28 | * of the queue is returned. If desiredmsgtype is |
| 29 | * greater than 0, then the first message of that type is returned. |
| 30 | * If desiredmsgtype is less than 0, the first |
| 31 | * message on the queue with a type less than or equal to the |
| 32 | * absolute value of desiredmsgtype will be read. |
| 33 | * If no messages match the criteria, your script will wait until a suitable |
| 34 | * message arrives on the queue. You can prevent the script from blocking |
| 35 | * by specifying MSG_IPC_NOWAIT in the |
| 36 | * flags parameter. |
| 37 | * @param int|null $msgtype The type of the message that was received will be stored in this |
| 38 | * parameter. |
| 39 | * @param int $maxsize The maximum size of message to be accepted is specified by the |
| 40 | * maxsize; if the message in the queue is larger |
| 41 | * than this size the function will fail (unless you set |
| 42 | * flags as described below). |
| 43 | * @param mixed $message The received message will be stored in message, |
| 44 | * unless there were errors receiving the message. |
| 45 | * @param bool $unserialize If set to |
| 46 | * TRUE, the message is treated as though it was serialized using the |
| 47 | * same mechanism as the session module. The message will be unserialized |
| 48 | * and then returned to your script. This allows you to easily receive |
| 49 | * arrays or complex object structures from other PHP scripts, or if you |
| 50 | * are using the WDDX serializer, from any WDDX compatible source. |
| 51 | * |
| 52 | * If unserialize is FALSE, the message will be |
| 53 | * returned as a binary-safe string. |
| 54 | * @param int $flags The optional flags allows you to pass flags to the |
| 55 | * low-level msgrcv system call. It defaults to 0, but you may specify one |
| 56 | * or more of the following values (by adding or ORing them together). |
| 57 | * |
| 58 | * Flag values for msg_receive |
| 59 | * |
| 60 | * |
| 61 | * |
| 62 | * MSG_IPC_NOWAIT |
| 63 | * If there are no messages of the |
| 64 | * desiredmsgtype, return immediately and do not |
| 65 | * wait. The function will fail and return an integer value |
| 66 | * corresponding to MSG_ENOMSG. |
| 67 | * |
| 68 | * |
| 69 | * |
| 70 | * MSG_EXCEPT |
| 71 | * Using this flag in combination with a |
| 72 | * desiredmsgtype greater than 0 will cause the |
| 73 | * function to receive the first message that is not equal to |
| 74 | * desiredmsgtype. |
| 75 | * |
| 76 | * |
| 77 | * MSG_NOERROR |
| 78 | * |
| 79 | * If the message is longer than maxsize, |
| 80 | * setting this flag will truncate the message to |
| 81 | * maxsize and will not signal an error. |
| 82 | * |
| 83 | * |
| 84 | * |
| 85 | * |
| 86 | * |
| 87 | * @param int|null $errorcode If the function fails, the optional errorcode |
| 88 | * will be set to the value of the system errno variable. |
| 89 | * @throws SemException |
| 90 | * |
| 91 | */ |
| 92 | function msg_receive($queue, int $desiredmsgtype, ?int &$msgtype, int $maxsize, &$message, bool $unserialize = \true, int $flags = 0, ?int &$errorcode = null): void |
| 93 | { |
| 94 | error_clear_last(); |
| 95 | $result = \msg_receive($queue, $desiredmsgtype, $msgtype, $maxsize, $message, $unserialize, $flags, $errorcode); |
| 96 | if ($result === \false) { |
| 97 | throw SemException::createFromPhpError(); |
| 98 | } |
| 99 | } |
| 100 | /** |
| 101 | * msg_remove_queue destroys the message queue specified |
| 102 | * by the queue. Only use this function when all |
| 103 | * processes have finished working with the message queue and you need to |
| 104 | * release the system resources held by it. |
| 105 | * |
| 106 | * @param resource $queue Message queue resource handle |
| 107 | * @throws SemException |
| 108 | * |
| 109 | */ |
| 110 | function msg_remove_queue($queue): void |
| 111 | { |
| 112 | error_clear_last(); |
| 113 | $result = \msg_remove_queue($queue); |
| 114 | if ($result === \false) { |
| 115 | throw SemException::createFromPhpError(); |
| 116 | } |
| 117 | } |
| 118 | /** |
| 119 | * msg_send sends a message of type |
| 120 | * msgtype (which MUST be greater than 0) to |
| 121 | * the message queue specified by queue. |
| 122 | * |
| 123 | * @param resource $queue Message queue resource handle |
| 124 | * @param int $msgtype The type of the message (MUST be greater than 0) |
| 125 | * @param mixed $message The body of the message. |
| 126 | * |
| 127 | * If serialize set to FALSE is supplied, |
| 128 | * MUST be of type: string, integer, float |
| 129 | * or bool. In other case a warning will be issued. |
| 130 | * @param bool $serialize The optional serialize controls how the |
| 131 | * message is sent. serialize |
| 132 | * defaults to TRUE which means that the message is |
| 133 | * serialized using the same mechanism as the session module before being |
| 134 | * sent to the queue. This allows complex arrays and objects to be sent to |
| 135 | * other PHP scripts, or if you are using the WDDX serializer, to any WDDX |
| 136 | * compatible client. |
| 137 | * @param bool $blocking If the message is too large to fit in the queue, your script will wait |
| 138 | * until another process reads messages from the queue and frees enough |
| 139 | * space for your message to be sent. |
| 140 | * This is called blocking; you can prevent blocking by setting the |
| 141 | * optional blocking parameter to FALSE, in which |
| 142 | * case msg_send will immediately return FALSE if the |
| 143 | * message is too big for the queue, and set the optional |
| 144 | * errorcode to MSG_EAGAIN, |
| 145 | * indicating that you should try to send your message again a little |
| 146 | * later on. |
| 147 | * @param int|null $errorcode If the function fails, the optional errorcode will be set to the value of the system errno variable. |
| 148 | * @throws SemException |
| 149 | * |
| 150 | */ |
| 151 | function msg_send($queue, int $msgtype, $message, bool $serialize = \true, bool $blocking = \true, ?int &$errorcode = null): void |
| 152 | { |
| 153 | error_clear_last(); |
| 154 | $result = \msg_send($queue, $msgtype, $message, $serialize, $blocking, $errorcode); |
| 155 | if ($result === \false) { |
| 156 | throw SemException::createFromPhpError(); |
| 157 | } |
| 158 | } |
| 159 | /** |
| 160 | * msg_set_queue allows you to change the values of the |
| 161 | * msg_perm.uid, msg_perm.gid, msg_perm.mode and msg_qbytes fields of the |
| 162 | * underlying message queue data structure. |
| 163 | * |
| 164 | * Changing the data structure will require that PHP be running as the same |
| 165 | * user that created the queue, owns the queue (as determined by the |
| 166 | * existing msg_perm.xxx fields), or be running with root privileges. |
| 167 | * root privileges are required to raise the msg_qbytes values above the |
| 168 | * system defined limit. |
| 169 | * |
| 170 | * @param resource $queue Message queue resource handle |
| 171 | * @param array $data You specify the values you require by setting the value of the keys |
| 172 | * that you require in the data array. |
| 173 | * @throws SemException |
| 174 | * |
| 175 | */ |
| 176 | function msg_set_queue($queue, array $data): void |
| 177 | { |
| 178 | error_clear_last(); |
| 179 | $result = \msg_set_queue($queue, $data); |
| 180 | if ($result === \false) { |
| 181 | throw SemException::createFromPhpError(); |
| 182 | } |
| 183 | } |
| 184 | /** |
| 185 | * sem_acquire by default blocks (if necessary) until the |
| 186 | * semaphore can be acquired. A process attempting to acquire a semaphore which |
| 187 | * it has already acquired will block forever if acquiring the semaphore would |
| 188 | * cause its maximum number of semaphore to be exceeded. |
| 189 | * |
| 190 | * After processing a request, any semaphores acquired by the process but not |
| 191 | * explicitly released will be released automatically and a warning will be |
| 192 | * generated. |
| 193 | * |
| 194 | * @param resource $sem_identifier sem_identifier is a semaphore resource, |
| 195 | * obtained from sem_get. |
| 196 | * @param bool $nowait Specifies if the process shouldn't wait for the semaphore to be acquired. |
| 197 | * If set to true, the call will return |
| 198 | * false immediately if a semaphore cannot be immediately |
| 199 | * acquired. |
| 200 | * @throws SemException |
| 201 | * |
| 202 | */ |
| 203 | function sem_acquire($sem_identifier, bool $nowait = \false): void |
| 204 | { |
| 205 | error_clear_last(); |
| 206 | $result = \sem_acquire($sem_identifier, $nowait); |
| 207 | if ($result === \false) { |
| 208 | throw SemException::createFromPhpError(); |
| 209 | } |
| 210 | } |
| 211 | /** |
| 212 | * sem_get returns an id that can be used to |
| 213 | * access the System V semaphore with the given key. |
| 214 | * |
| 215 | * A second call to sem_get for the same key |
| 216 | * will return a different semaphore identifier, but both |
| 217 | * identifiers access the same underlying semaphore. |
| 218 | * |
| 219 | * If key is 0, a new private semaphore |
| 220 | * is created for each call to sem_get. |
| 221 | * |
| 222 | * @param int $key |
| 223 | * @param int $max_acquire The number of processes that can acquire the semaphore simultaneously |
| 224 | * is set to max_acquire. |
| 225 | * @param int $perm The semaphore permissions. Actually this value is |
| 226 | * set only if the process finds it is the only process currently |
| 227 | * attached to the semaphore. |
| 228 | * @param int $auto_release Specifies if the semaphore should be automatically released on request |
| 229 | * shutdown. |
| 230 | * @return resource Returns a positive semaphore identifier on success. |
| 231 | * @throws SemException |
| 232 | * |
| 233 | */ |
| 234 | function sem_get(int $key, int $max_acquire = 1, int $perm = 0666, int $auto_release = 1) |
| 235 | { |
| 236 | error_clear_last(); |
| 237 | $result = \sem_get($key, $max_acquire, $perm, $auto_release); |
| 238 | if ($result === \false) { |
| 239 | throw SemException::createFromPhpError(); |
| 240 | } |
| 241 | return $result; |
| 242 | } |
| 243 | /** |
| 244 | * sem_release releases the semaphore if it |
| 245 | * is currently acquired by the calling process, otherwise |
| 246 | * a warning is generated. |
| 247 | * |
| 248 | * After releasing the semaphore, sem_acquire |
| 249 | * may be called to re-acquire it. |
| 250 | * |
| 251 | * @param resource $sem_identifier A Semaphore resource handle as returned by |
| 252 | * sem_get. |
| 253 | * @throws SemException |
| 254 | * |
| 255 | */ |
| 256 | function sem_release($sem_identifier): void |
| 257 | { |
| 258 | error_clear_last(); |
| 259 | $result = \sem_release($sem_identifier); |
| 260 | if ($result === \false) { |
| 261 | throw SemException::createFromPhpError(); |
| 262 | } |
| 263 | } |
| 264 | /** |
| 265 | * sem_remove removes the given semaphore. |
| 266 | * |
| 267 | * After removing the semaphore, it is no longer accessible. |
| 268 | * |
| 269 | * @param resource $sem_identifier A semaphore resource identifier as returned |
| 270 | * by sem_get. |
| 271 | * @throws SemException |
| 272 | * |
| 273 | */ |
| 274 | function sem_remove($sem_identifier): void |
| 275 | { |
| 276 | error_clear_last(); |
| 277 | $result = \sem_remove($sem_identifier); |
| 278 | if ($result === \false) { |
| 279 | throw SemException::createFromPhpError(); |
| 280 | } |
| 281 | } |
| 282 | /** |
| 283 | * shm_put_var inserts or updates the |
| 284 | * variable with the given |
| 285 | * variable_key. |
| 286 | * |
| 287 | * Warnings (E_WARNING level) will be issued if |
| 288 | * shm_identifier is not a valid SysV shared memory |
| 289 | * index or if there was not enough shared memory remaining to complete your |
| 290 | * request. |
| 291 | * |
| 292 | * @param resource $shm_identifier A shared memory resource handle as returned by |
| 293 | * shm_attach |
| 294 | * @param int $variable_key The variable key. |
| 295 | * @param mixed $variable The variable. All variable types |
| 296 | * that serialize supports may be used: generally |
| 297 | * this means all types except for resources and some internal objects |
| 298 | * that cannot be serialized. |
| 299 | * @throws SemException |
| 300 | * |
| 301 | */ |
| 302 | function shm_put_var($shm_identifier, int $variable_key, $variable): void |
| 303 | { |
| 304 | error_clear_last(); |
| 305 | $result = \shm_put_var($shm_identifier, $variable_key, $variable); |
| 306 | if ($result === \false) { |
| 307 | throw SemException::createFromPhpError(); |
| 308 | } |
| 309 | } |
| 310 | /** |
| 311 | * Removes a variable with a given variable_key |
| 312 | * and frees the occupied memory. |
| 313 | * |
| 314 | * @param resource $shm_identifier The shared memory identifier as returned by |
| 315 | * shm_attach |
| 316 | * @param int $variable_key The variable key. |
| 317 | * @throws SemException |
| 318 | * |
| 319 | */ |
| 320 | function shm_remove_var($shm_identifier, int $variable_key): void |
| 321 | { |
| 322 | error_clear_last(); |
| 323 | $result = \shm_remove_var($shm_identifier, $variable_key); |
| 324 | if ($result === \false) { |
| 325 | throw SemException::createFromPhpError(); |
| 326 | } |
| 327 | } |
| 328 | /** |
| 329 | * shm_remove removes the shared memory |
| 330 | * shm_identifier. All data will be destroyed. |
| 331 | * |
| 332 | * @param resource $shm_identifier The shared memory identifier as returned by |
| 333 | * shm_attach |
| 334 | * @throws SemException |
| 335 | * |
| 336 | */ |
| 337 | function shm_remove($shm_identifier): void |
| 338 | { |
| 339 | error_clear_last(); |
| 340 | $result = \shm_remove($shm_identifier); |
| 341 | if ($result === \false) { |
| 342 | throw SemException::createFromPhpError(); |
| 343 | } |
| 344 | } |
| 345 |