00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 final class MessageSegmentHandler implements SegmentHandler
00017 {
00018 private $id = null;
00019
00020 public function __construct($segmentId)
00021 {
00022 $this->id = $segmentId;
00023 }
00024
00025 public function touch($key)
00026 {
00027 try {
00028 $q = msg_get_queue($this->id, ONPHP_IPC_PERMS);
00029 } catch (BaseException $e) {
00030
00031 return false;
00032 }
00033
00034 try {
00035 return msg_send($q, $key, 1, false, false);
00036 } catch (BaseException $e) {
00037
00038 $msg = $type = null;
00039
00040 msg_receive($q, -(PHP_INT_MAX), $type, 2, $msg, false);
00041
00042 try {
00043 return msg_send($q, $key, 1, false, false);
00044 } catch (BaseException $e) {
00045
00046 return false;
00047 }
00048 }
00049
00050 Assert::isUnreachable();
00051 }
00052
00053 public function unlink($key)
00054 {
00055 try {
00056 $q = msg_get_queue($this->id, ONPHP_IPC_PERMS);
00057 } catch (BaseException $e) {
00058
00059 return false;
00060 }
00061
00062 $type = $msg = null;
00063
00064 return msg_receive($q, $key, $type, 2, $msg, false, MSG_IPC_NOWAIT);
00065 }
00066
00067 public function ping($key)
00068 {
00069 try {
00070 $q = msg_get_queue($this->id, ONPHP_IPC_PERMS);
00071 } catch (BaseException $e) {
00072
00073 return false;
00074 }
00075
00076 $type = $msg = null;
00077
00078
00079 if (msg_receive($q, $key, $type, 2, $msg, false, MSG_IPC_NOWAIT)) {
00080 try {
00081 msg_send($q, $key, 1, false, false);
00082 } catch (BaseException $e) {}
00083
00084 return true;
00085 }
00086
00087 return false;
00088 }
00089
00090 public function drop()
00091 {
00092 try {
00093 $q = msg_get_queue($this->id, ONPHP_IPC_PERMS);
00094 } catch (BaseException $e) {
00095
00096 return true;
00097 }
00098
00099 if (!msg_remove_queue($q)) {
00100
00101 $type = $msg = null;
00102
00103 while (msg_receive($q, 0, $type, 2, $msg, false, MSG_IPC_NOWAIT)) {
00104
00105 }
00106 }
00107
00108 return true;
00109 }
00110 }
00111 ?>