/** * Sending message test */ public function testMessage() { $this->assertInternalType('string', Messenger::message('test', 'test')); }
/** * Push to task event * * @param ConnectionInterface $conn * @param ConnectionInterface $request * @throws \Sonar\Exceptions\AppServiceException */ public function onMessage(ConnectionInterface $conn, $request) { if (is_array($request = json_decode($request, true)) === false) { throw new AppServiceException('The server received an invalid data format'); } if (isset($request['page']) === false) { throw new AppServiceException('There is no current page data'); } $this->queueService->push($request, function () use($request, $conn) { // process only what is necessary for the subsequent construction of stats return ['ip' => $this->getIpAddress($conn), 'hash' => md5($this->getIpAddress($conn) . $this->getUserAgent($conn)), 'open' => time()]; }); // send back if (defined('SONAR_VERBOSE') === true) { echo Messenger::message(json_encode($request)); $conn->send(json_encode($request)); } }