本文整理汇总了PHP中msg_receive函数的典型用法代码示例。如果您正苦于以下问题:PHP msg_receive函数的具体用法?PHP msg_receive怎么用?PHP msg_receive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了msg_receive函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readQueuedIssues
/**
*
*/
public function readQueuedIssues()
{
// Read the entire queue and write all issues to the
// base collector
// Get the status of the queue
$status = msg_stat_queue($this->message_queue_resource);
// Read messages while there are still messages on
// the queue
while ($status['msg_qnum'] > 0) {
$message = null;
$message_type = 0;
// Receive the message, populating $message by
// reference
if (false !== msg_receive($this->message_queue_resource, self::MESSAGE_TYPE_ISSUE, $message_type, 2048, $message, true)) {
assert($message instanceof IssueInstance, "Messages must be of type IssueInstance.");
// Cast the message to an IssueInstance
if ($message instanceof IssueInstance) {
$this->collectIssue($message);
}
} else {
break;
}
$status = msg_stat_queue($this->message_queue_resource);
}
}
示例2: receive
/**
* Waits for and receives a message
* @param integer $type
* @return mixed
*/
public function receive($type)
{
$rcvType = 0;
$msg = '';
msg_receive($this->queue, $type, $rcvType, $this->size, $msg);
return $msg;
}
示例3: actionDequeue
public function actionDequeue($qId, $data)
{
$q = msg_get_queue($qId);
$r = msg_receive($q, 1, $msgType, 10000, $msg);
echo "Result: " . $r . "<br/>";
echo " Got msg: " . $msg;
}
示例4: pop
/**
* {@inheritdoc}
*/
public function pop()
{
if (!msg_receive($this->getQueue(), -time(), $eta, $this->itemMaxLength, $item, $this->serialize, MSG_IPC_NOWAIT, $errorCode)) {
throw MSG_ENOMSG === $errorCode ? new NoItemAvailableException($this) : new QueueException($this, self::getErrorMessage($errorCode), $errorCode);
}
return $item;
}
示例5: peek
function peek()
{
$this->init();
$flags = $this->blocking && !$this->blockingTimeout ? 0 : MSG_IPC_NOWAIT;
if (!$this->blockingTimeout || !$this->blocking) {
msg_receive($this->seg, 1, $msgtype, $this->maxMsgSize, $message, false, $flags, $errno);
} else {
$timeout = new Scalr_Util_Timeout($this->blockingTimeout);
try {
while (!$message && !$timeout->reached()) {
if (!msg_receive($this->seg, 1, $msgtype, $this->maxMsgSize, $message, false, $flags, $errno)) {
$timeout->sleep(10);
}
}
} catch (Scalr_Util_TimeoutException $e) {
return null;
}
}
if ($message) {
return unserialize($message);
} else {
if ($errno == MSG_ENOMSG && !$this->blocking) {
return null;
}
if ($errno == 22) {
return null;
}
throw new Scalr_System_Ipc_Exception($errno ? self::$msgrcv_errors[$errno] : "Cannot receive message", $errno);
}
}
示例6: collectFiles
/**
* 从消息队列中获取要监控的文件列表
* @param bool $block
* @return void
*/
protected function collectFiles($block = false)
{
$msg_type = $message = null;
$flag = $block ? 0 : MSG_IPC_NOWAIT;
if (@msg_receive(\Man\Core\Master::getQueueId(), self::MSG_TYPE_FILE_MONITOR, $msg_type, 10000, $message, true, $flag)) {
// 被排除的路径
$exclude_path = array();
// 因为配置可能会被更改,所以每次都会重新从配置中查找排除路径
$config_exclude_path = $this->getExcludeFiles();
foreach ($config_exclude_path as $path) {
if ($real_path = realpath($path)) {
$exclude_path[] = $real_path;
}
}
foreach ($message as $file) {
$is_exclude_file = false;
foreach ($exclude_path as $path) {
// 是被排除的文件
if (0 === strpos($file, $path)) {
$is_exclude_file = true;
break;
}
}
if (!$is_exclude_file && !isset($this->filesToInotify[$file])) {
$stat = @stat($file);
$mtime = isset($stat['mtime']) ? $stat['mtime'] : 0;
$this->filesToInotify[$file] = $mtime;
}
}
}
}
示例7: mqRead
static function mqRead($name, $want = 0, $wait = true)
{
$mq = msg_get_queue(self::_ftok($name));
$type = null;
// Recieved Message Type
$size = 8192;
// Max Message Size
$mess = null;
// Recieved Message Data
$unser = true;
$flags = 0;
$error = null;
if ($wait == false) {
$flags |= MSG_IPC_NOWAIT;
}
if (msg_receive($mq, $want, $type, $size, $mess, $unser, $flags, $error)) {
return $mess;
}
Radix::dump($mq);
Radix::dump($want);
Radix::dump($type);
Radix::dump($size);
Radix::dump($mess);
Radix::dump($unser);
Radix::dump($flags);
Radix::dump($error);
exit;
}
示例8: process
private function process()
{
$messageType = NULL;
$messageMaxSize = 1024;
while (TRUE) {
if (count($this->childs) < $this->max) {
echo count($this->childs) . " ";
if (msg_receive($this->queue, QUEUE_TYPE_START, $messageType, $messageMaxSize, $this->message)) {
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork' . PHP_EOL);
} else {
if ($pid) {
$this->childs[$pid] = TRUE;
$messageType = NULL;
$this->message = NULL;
} else {
sleep(3);
$this->complete($messageType, $this->message);
exit;
}
}
foreach ($this->childs as $pid => $value) {
if (pcntl_waitpid($pid, $status, WNOHANG)) {
if (pcntl_wifexited($status)) {
unset($this->childs[$pid]);
}
}
}
}
}
sleep(1);
}
}
示例9: pickup
public function pickup()
{
if (msg_receive($this->queue, $this->msgtype_receive, $msgtype_erhalten, $this->maxsize, $daten, $this->serialize_needed, $this->option_receive, $err) === true) {
return $daten;
} else {
//var_dump($err);
}
}
示例10: pop
function pop()
{
$ret = msg_receive($this->msg, 0, $this->msgtype, 65525, $data);
if ($ret) {
return $data;
}
return false;
}
示例11: receive
public function receive($block = false, $serialize = false)
{
$data = [];
$error = 0;
$type = 1;
$block = $block ? MSG_NOERROR : MSG_IPC_NOWAIT;
$res = msg_receive($this->msg, $type, $type, 1024, $data, $serialize, $block, $error);
return $res ? $data : null;
}
示例12: receiveMessage
/**
* @return string
* @throws \RuntimeException
*/
protected function receiveMessage()
{
$msgtype = $message = null;
// argument #3: specify the maximum number of bytes allowsed in one message queue.
$success = msg_receive($this->id, 1, $msgtype, $this->stat['msg_qbytes'], $message, false);
if (!$success) {
throw new \RuntimeException('failed to receive message.');
}
return $message;
}
示例13: receive
public function receive($type = 0, &$msgtype = null)
{
if (!msg_receive($this->queue, $type, $msgtype, 65535, $msgdata, true, MSG_IPC_NOWAIT, $error)) {
if ($error == MSG_ENOMSG) {
return null;
}
debug("Error reading from IPC queue 0x%x: %s", $this->key, $error);
return null;
}
return $msgdata;
}
示例14: readAction
public function readAction()
{
$msg_id = msg_get_queue($this->_key, 0600);
while (true) {
if (msg_receive($msg_id, 1, $msg_type, 16384, $msg, true, 0, $msg_error)) {
list($id, $msg) = split('!', $msg);
echo json_encode(array('id' => $id, 'msg' => $msg));
}
}
msg_remove_queue($msg_id);
}
示例15: handle
public function handle()
{
$messageQueueKey = ftok(App::path('cache') . "/queue/daemon.queue", "a");
$messageQueue = msg_get_queue($messageQueueKey, 0666);
$count = 0;
while ($count < 5) {
msg_receive($messageQueue, 0, $messageType, 1024, $message, true, MSG_IPC_NOWAIT);
File::appendText(App::path('cache') . "/" . __CLASS__ . ".txt", $message);
sleep(2);
}
}