function processQueue($queueUrls) { try { foreach ($queueUrls as $url) { $fileData = file_get_contents($this->getLinkedInCall($url)); if ($fileData === FALSE) { $this->errorQueue[] = $url; continue; } $output = str_replace(array('IN.Tags.Share.handleCount(', ');'), '', trim($fileData)); if ($output !== FALSE) { $json = json_decode($output); unset($fileData); // free memory $count = intval($json->count); $statistic = URLStatistics::get()->filter(array('URL' => $url, 'Service' => $this->service, 'Action' => $this->statistic))->first(); if (!$statistic || !$statistic->exists()) { $statistic = URLStatistics::create(); $statistic->URL = $url; $statistic->Service = $this->service; $statistic->Action = $this->statistic; } $statistic->Count = $count; $statistic->write(); } } } catch (Exception $e) { return 0; } return $this->errorQueue; }
public function setUp() { parent::setUp(); SocialQueue::queueURL($this->testURL); // now setup a statistics for the URL foreach ($this->services as $service) { $countService = new $service(); if (is_array($countService->statistic)) { foreach ($countService->statistic as $statistic) { $stat = URLStatistics::create(); $stat->Service = $countService->service; $stat->Action = $statistic; $stat->Count = 50; $stat->URL = $this->testURL; $stat->write(); } } else { $stat = URLStatistics::create(); $stat->Service = $countService->service; $stat->Action = $countService->statistic; $stat->Count = 50; $stat->URL = $this->testURL; $stat->write(); unset($stat); } } }
public function processQueue($queueUrls) { try { foreach ($queueUrls as $url) { $twitter = new SSTwitter(); $reply = $twitter->search($url); if ($reply->errors) { $this->errorQueue[] = $url; continue; } $metadata = $reply->statuses; $count = intval($metadata[0]->user->statuses_count); $id = $entry['ID']; $statistic = URLStatistics::get()->filter(array('URL' => $url, 'Service' => $this->service, 'Action' => $this->statistic))->first(); if (!$statistic || !$statistic->exists()) { $statistic = URLStatistics::create(); $statistic->URL = $url; $statistic->Service = $this->service; $statistic->Action = $this->statistic; } $statistic->Count = $count; $statistic->write(); } } catch (Exception $e) { return 0; } return $this->errorQueue; }
function processQueue($queueUrls) { try { foreach ($queueUrls as $url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "https://clients6.google.com/rpc"); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json')); $curl_results = curl_exec($curl); if (curl_errno($curl)) { $this->errorQueue[] = $url; continue; } curl_close($curl); $json = json_decode($curl_results, true); if (isset($json['error'])) { $this->errorQueue[] = $url; continue; } $count = intval($json[0]['result']['metadata']['globalCounts']['count']); $statistic = URLStatistics::get()->filter(array('URL' => $url, 'Service' => $this->service, 'Action' => $this->statistic))->first(); if (!$statistic || !$statistic->exists()) { $statistic = URLStatistics::create(); $statistic->URL = $url; $statistic->Service = $this->service; $statistic->Action = $this->statistic; } $statistic->Count = $count; $statistic->write(); } } catch (Exception $e) { return 0; } return $this->errorQueue; }
public function processQueue($queueUrls) { $urls = array(); $noEntries = count($queueUrls); $i = 0; $step = 0; try { foreach ($queueUrls as $url) { $i++; $step++; $urls[] = $url; if ($i == $this->requestCount || $step == $noEntries) { $fileData = file_get_contents($this->getFacebookCall($urls)); if ($fileData === false) { foreach ($urls as $errorUrl) { $this->errorQueue[] = $url; } } else { $xml = simplexml_load_string($fileData); if ($xml->error_code || !$xml->link_stat) { foreach ($urls as $errorUrl) { $this->errorQueue[] = $url; continue; } } $results = $xml->link_stat; $ids = array_flip($urls); foreach ($results as $result) { $resultUrl = (string) $result->url; $statistics = URLStatistics::get()->filter(array('URL' => $resultUrl, 'Service' => $this->service, 'Action' => $this->statistic)); if ($statistics && $statistics->exists()) { foreach ($statistics as $statistic) { $statistic->Count = (int) $result->{$statistic->Action}; $statistic->write(); } } else { foreach ($this->statistic as $countStat) { $statistic = URLStatistics::create(); $statistic->URL = $resultUrl; $statistic->Service = $this->service; $statistic->Action = $countStat; $statistic->Count = (int) $result->{$statistic->Action}; $statistic->write(); } } // sanity check what should be in the db and what is actually in it if (count($this->statistic) != $statistics->count()) { foreach ($this->statistic as $statistic) { if ($result->{$statistic}) { // do we have this in the db $stat = URLStatistics::get()->filter(array('URL' => $resultUrl, 'Service' => $this->service, 'Action' => $statistic))->first(); if (!$stat || !$stat->exists()) { $stat = URLStatistics::create(); $stat->URL = $resultUrl; $stat->Service = $this->service; $stat->Action = $statistic; $stat->Count = (int) $result->{$statistic}; $stat->write(); } } } } } } unset($fileData); // free memory $i = 0; $urls = array(); } } } catch (Exception $e) { return 0; } return $this->errorQueue; }