5 * Pings all URLs that have not been pinged yet
13 public function __construct(Dependencies $deps)
16 $this->db = $deps->db;
17 $this->log = $deps->log;
19 $this->pbc = new \PEAR2\Services\Pingback\Client();
21 $req = new \HTTP_Request2();
24 'ssl_verify_peer' => false,
25 'ssl_verify_host' => false
28 $this->pbc->setRequest($req);
29 $this->pbc->setDebug(true);
32 public function pingAll()
34 $this->log->info('Pinging all URLs..');
35 $res = $this->db->query(
36 'SELECT fe_url, feu_id, feu_url FROM feedentries, feedentryurls'
37 . ' WHERE fe_id = feu_fe_id' . $this->sqlNeedsUpdate()
40 while ($row = $res->fetch(\PDO::FETCH_OBJ)) {
42 'Pinging URL #%d: %s', $row->feu_id, $row->feu_url
47 $this->log->info('Finished pinging %d URLs.', $items);
50 public function pingSome($urlOrIds)
53 foreach ($urlOrIds as $urlOrId) {
54 if (is_numeric($urlOrId)) {
55 $options[] = 'feu_id = ' . intval($urlOrId);
57 $options[] = 'feu_url = ' . $this->db->quote($urlOrId);
61 $this->log->info('Pinging %d URLs..', count($options));
62 $res = $this->db->query(
63 'SELECT fe_url, feu_id, feu_url FROM feedentries, feedentryurls'
64 . ' WHERE fe_id = feu_fe_id'
65 . $this->sqlNeedsUpdate()
66 . ' AND (' . implode(' OR ', $options) . ')'
69 while ($row = $res->fetch(\PDO::FETCH_OBJ)) {
71 'Pinging URL #%d: %s', $row->feu_id, $row->feu_url
76 $this->log->info('Finished pinging %d URLs.', $items);
79 public function ping($row)
85 $res = $this->pbc->send($from, $to);
86 } catch (\Exception $e) {
87 $this->log->err('Exception: ' . $e->getMessage());
89 'UPDATE feedentryurls SET'
91 . ', feu_updated = NOW()'
92 . ', feu_error = ' . $this->db->quote($e->getMessage())
93 . ' WHERE feu_id = ' . $this->db->quote($row->feu_id)
98 if (!$res->isError()) {
100 $this->log->info('ok');
102 'UPDATE feedentryurls SET'
104 . ', feu_updated = NOW()'
106 . ' WHERE feu_id = ' . $this->db->quote($row->feu_id)
110 $this->log->err('Error: ' . $res->getCode() . ': ' . $res->getMessage());
111 $httpRes = $res->getResponse();
114 'Pingback response: Status code ' . $httpRes->getStatus()
115 . ', headers: ' . print_r($httpRes->getHeader(), true)
116 . ', body: ' . $httpRes->getBody()
120 'UPDATE feedentryurls SET'
122 . ', feu_updated = NOW()'
124 . $this->db->quote($res->getCode() . ': ' . $res->getMessage())
125 . ' WHERE feu_id = ' . $this->db->quote($row->feu_id)
130 protected function sqlNeedsUpdate()
132 if ($this->deps->options['force']) {
135 return ' AND feu_active = 1 AND feu_pinged = 0';