/**
  * @param string $status
  */
 public function tweet($status)
 {
     $postId = $this->redisClient->incr("global:nextPostId");
     $userId = $this->session->get('userId');
     $post = $userId . "|" . (new \DateTime())->format('d/m/y') . "|" . $status;
     $this->redisClient->set("post:{$postId}", $post);
     $followers = $this->redisClient->smembers("uid:" . $userId . ":followers");
     if ($followers === false) {
         $followers = [];
     }
     $followers[] = $userId;
     foreach ($followers as $fid) {
         $this->redisClient->lpush("uid:{$fid}:posts", [$postId]);
     }
     $this->redisClient->lpush("global:timeline", [$postId]);
     $this->redisClient->ltrim("global:timeline", 0, 1000);
 }
Example #2
0
 public function Job_Lookup_Word()
 {
     $word = $this->job_details->word;
     $this->status = 'working';
     $this->Report();
     try {
         $url = 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/' . urlencode($word) . '?key=' . DICTIONARY_API_KEY;
         $contents = @file_get_contents($url);
         /*
          * I really don't know how to manipulate very complex XML easily in PHP,
          * so please ignore the hideous hacks that you are about to see.
          */
         $xml = new SimpleXMLElement($contents);
         $results = $xml->xpath('/entry_list/entry[1]//dt');
         $return = '';
         foreach ($results as $node) {
             /* @var $node SimpleXMLElement */
             $string = $node->asXML();
             // Please ignore the developer behind the curtain
             $string = str_replace('<dt>:', '', $string);
             $string = str_replace(':</dt>', '', $string);
             $def = trim(strip_tags($string));
             // Return the longest definition
             if (strlen($def) > strlen($return)) {
                 $return = $def;
             }
         }
     } catch (Exception $ex) {
         $def = "{$word} failed: " . $ex->getMessage();
     }
     // Okay, you can start paying attention again now.
     $json = json_encode(array('word' => $word, 'def' => $def));
     $this->last_word = $word;
     $this->last_def = $def;
     echo "\n {$word}: {$return} \n";
     $this->redis->lpush('word.defs', $json);
     $this->redis->ltrim('word.defs', 0, 20);
     $this->beanstalk->delete($this->job);
     // Wait 2 seconds so we don't overload the API
     usleep(2000000);
 }
 public function clearErrors()
 {
     $this->redisClient->ltrim($this->errorKey, 100, -1);
 }