@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | { |
63 | 63 | $this->curl = $curl; |
64 | 64 | $this->kvPrefix = $kvPrefix; |
65 | - $this->sessionTTL = (int)$sessionTTL; |
|
65 | + $this->sessionTTL = (int) $sessionTTL; |
|
66 | 66 | //If we cannot connect to Consul on start, we have a problem. |
67 | 67 | $this->createSession(); |
68 | 68 | $this->lastSuccessfullCheck = time(); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | public function heartbeat() |
100 | 100 | { |
101 | 101 | //If we have last successfull check recently new, we don't have to do anything |
102 | - if ($this->lastSuccessfullCheck !== null && time() - $this->lastSuccessfullCheck < $this->sessionTTL / 2 ) { |
|
102 | + if ($this->lastSuccessfullCheck !== null && time()-$this->lastSuccessfullCheck < $this->sessionTTL / 2) { |
|
103 | 103 | return false; |
104 | 104 | } |
105 | 105 | //If session reneval succeedes, update last successfull check. |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | } catch (RuntimeException $e) { |
117 | 117 | //We could not create new session. We can work for some time in 'detached' mode, |
118 | 118 | //but if our TTL time runs out, we have to throw an exception. |
119 | - if ($this->lastSuccessfullCheck === null || time() - $this->lastSuccessfullCheck >= $this->sessionTTL) { |
|
119 | + if ($this->lastSuccessfullCheck === null || time()-$this->lastSuccessfullCheck >= $this->sessionTTL) { |
|
120 | 120 | throw $e; |
121 | 121 | } |
122 | 122 | return false; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | //Check, if we don't have existing value for the session |
135 | 135 | $currentValue = $this->curl->performGetRequest('/kv/'.$this->kvPrefix.$this->sessionId); |
136 | 136 | if (!empty($currentValue['Value'])) { |
137 | - return (int)base64_decode($currentValue['Value']); |
|
137 | + return (int) base64_decode($currentValue['Value']); |
|
138 | 138 | } |
139 | 139 | //Lock main key to block concurrent checks |
140 | 140 | $this->lockKey(); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | } |
150 | 150 | //Release the lock on the main key and return machine ID. |
151 | 151 | $this->releaseKey(); |
152 | - return (int)$machineId; |
|
152 | + return (int) $machineId; |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -166,10 +166,10 @@ discard block |
||
166 | 166 | if ($currentValue['Key'] == $this->kvPrefix) { |
167 | 167 | continue; |
168 | 168 | } elseif ($currentValue['Key'] == $this->sessionId) { |
169 | - return (int)base64_decode($currentValue['Value']); |
|
169 | + return (int) base64_decode($currentValue['Value']); |
|
170 | 170 | } |
171 | 171 | else { |
172 | - $usedIds[] = (int)base64_decode($currentValue['Value']); |
|
172 | + $usedIds[] = (int) base64_decode($currentValue['Value']); |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | for ($k = 0; $k < 1024; $k++) { |
@@ -209,12 +209,12 @@ discard block |
||
209 | 209 | */ |
210 | 210 | private function createSession() |
211 | 211 | { |
212 | - $url ='/session/create'; |
|
212 | + $url = '/session/create'; |
|
213 | 213 | //We create new session with given TTL and with lock delay equal to half of TTL. |
214 | 214 | $payload = array( |
215 | 215 | 'TTL' => $this->sessionTTL.'s', |
216 | 216 | "Behavior" => "delete", |
217 | - 'LockDelay' => floor($this->sessionTTL/2).'s', |
|
217 | + 'LockDelay' => floor($this->sessionTTL / 2).'s', |
|
218 | 218 | ); |
219 | 219 | $returnData = $this->curl->performPutRequest($url, json_encode($payload)); |
220 | 220 | if (empty($returnData['ID'])) { |