PHP code example of takuya / php-sysv-ipc-message-queue
1. Go to this page and download the library: Download takuya/php-sysv-ipc-message-queue library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
takuya / php-sysv-ipc-message-queue example snippets
$q = new IPCMsgQueue('my-named-queue');
$msg = 'random string';
$q->push($msg);
$q = new IPCMsgQueue('my-named-queue');
$arr = ['a'=>1];
$q->push($msg=$arr);
// retrieve data as send.
$result = $q->pop();
// same to send
$arr == $result #=> true
## large bytes
$msg = str_rand(1024);
$q = new IPCMsgQueue('my-named-queue');
$q->push($msg);
// will be not same to $msg.
$result = $q->pop();
// to get same data,specify large size.
$result = $q->pop(null,strlen(serialize($msg)));// will be 10 byte larger.
use Takuya\PhpSysvMessageQueue\IPCMsgQueue;
$q = new IPCMsgQueue('my-named-queue');
$q->push('message');
$q->pop();
$q->destroy();
$q = new IPCMsgQueue('my-named-queue');
// push some messages
$q->push('msg');
$q->push('msg');
$q->push('msg');
// save before shutdown.
$q->save('path/to/permanent/file');
$q = new IPCMsgQueue('my-named-queue');
// load after system restarted.
$q->load('path/to/permanent/file');
// can read data
$q->pop()#=>'msg';
$q->pop()#=>'msg';
$q->pop()#=>'msg';