-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPublisher.php
More file actions
104 lines (83 loc) · 2.34 KB
/
Publisher.php
File metadata and controls
104 lines (83 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace phpqueue;
/**
* This file is part of the phpqueue library.
*
* (c) Juan Berzal <[email protected]>
*
* This source file is subject to the MIT license.
*/
class Publisher
{
private $msgkey;
private $message;
private $serialize_needed;
private $block_send;
private $msgtype_send;
private $queue;
/*
* @package phpqueue
* @author Juan Berzal <[email protected]>
*/
public function __construct($argument = '')
{
$settings = array(
'msgkey' => md5(uniqid(microtime(), true)),
'serialize_needed' => false,
//'block_send' => false, // unblock
'block_send' => true, // block
'msgtype_send' => 1
);
if(!empty($argument)){
foreach($argument as $key => $val){
if(!empty($val)){
$settings[$key] = $val;
}
}
}
$this->msgkey = $settings['msgkey'];
$this->message = array();
$this->serialize_needed = $settings['serialize_needed'];
$this->block_send = $settings['block_send'];
$this->msgtype_send = $settings['msgtype_send'];
}
public function setMsgkey($msgkey){
$this->msgkey = $msgkey;
}
public function getMsgkey(){
return $this->msgkey;
}
public function setMessage($message){
$this->message = $message;
}
public function getMessage(){
return $this->message;
}
public function serialize_needed($serialize_needed){
$this->serialize_needed = $serialize_needed;
}
public function setBlock_send($block_send){
$this->block_send = $block_send;
}
public function setMsgtype_send($msgtype_send){
$this->msgtype_send = $msgtype_send;
}
public function setQueue($key){
$this->queue = msg_get_queue($key);
}
public function publish(){
$resend = array();
if (is_array($this->message)) {
foreach ($this->message as $value) {
if (!msg_send($this->queue,$this->msgtype_send, $value, $this->serialize_needed, $this->block_send, $err)) {
$resend[] = $value;
}
}
} else{
if (!msg_send($this->queue,$this->msgtype_send, $this->message, $this->serialize_needed, $this->block_send, $err)) {
$resend[] = $value;
}
}
return $resend;
}
}