/** * Processes a queue file and does something with it (example only) * @param string $queueFile The queue file */ protected function processQueueFile($queueFile) { Logger::debug('Processing file: ' . $queueFile); // Open file $fp = fopen($queueFile, 'r'); // Check if something has gone wrong, or perhaps the file is just locked by another process if (!is_resource($fp)) { Logger::error('WARN: Unable to open file or file already open: ' . $queueFile . ' - Skipping.'); return FALSE; } // Lock file flock($fp, LOCK_EX); // Loop over each line (1 line per status) $statusCounter = 0; while ($rawStatus = fgets($fp, 8192)) { $statusCounter++; $status = json_decode($rawStatus, TRUE); // convert JSON data into PHP array // if data is invalid (e.g., if a user has deleted a tweet; surprisingly frequent) if (is_array($status) == FALSE || !isset($status['user']['id_str'])) { Logger::debug('Status is invalid, continuing.'); continue; // skip it } if (array_key_exists(0, $status['entities']['urls']) == FALSE) { // if tweet does not contain link continue; // skip it } /* Weed out statuses created by undesired user. (The streaming API also returns _retweets of_ ** statuses by desired user, which we don't want.) */ if (!\OpenFuego\app\Universe::isCitizen($status['user']['id_str'])) { // if the tweeter is not a citizen continue; // skip it } $this->processUrls($status); Logger::debug('Decoded tweet: ' . $status['user']['screen_name'] . ': ' . urldecode($status['text'])); set_time_limit(60); unset($status, $entities); } // End while // Release lock and close flock($fp, LOCK_UN); fclose($fp); // All done with this file Logger::debug('Successfully processed ' . $statusCounter . ' tweets from ' . $queueFile . ' - deleting.'); unset($rawStatus); unlink($queueFile); }
public static function getInfluence($user_id_str) { try { $dbh = self::getDbh(); $sql = "SELECT influence FROM openfuego_citizens WHERE user_id = :user_id LIMIT 1;"; $sth = self::$dbh->prepare($sql); $sth->bindParam('user_id', $user_id_str); $sth->execute(); $influence = $sth->fetchColumn(0); return $influence; } catch (\PDOException $e) { Logger::error($e); return FALSE; } }