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, feu_tries'
37 . ' FROM feedentries, feedentryurls'
38 . ' WHERE fe_id = feu_fe_id' . $this->sqlNeedsUpdate()
41 while ($row = $res->fetch(\PDO::FETCH_OBJ)) {
43 'Pinging URL #%d: %s', $row->feu_id, $row->feu_url
48 $this->log->info('Finished pinging %d URLs.', $items);
51 public function pingSome($urlOrIds)
54 foreach ($urlOrIds as $urlOrId) {
55 if (is_numeric($urlOrId)) {
56 $options[] = 'feu_id = ' . intval($urlOrId);
58 $options[] = 'feu_url = ' . $this->db->quote($urlOrId);
62 $this->log->info('Pinging %d URLs..', count($options));
63 $res = $this->db->query(
64 'SELECT fe_url, feu_id, feu_url FROM feedentries, feedentryurls'
65 . ' WHERE fe_id = feu_fe_id'
66 . $this->sqlNeedsUpdate()
67 . ' AND (' . implode(' OR ', $options) . ')'
70 while ($row = $res->fetch(\PDO::FETCH_OBJ)) {
72 'Pinging URL #%d: %s', $row->feu_id, $row->feu_url
77 $this->log->info('Finished pinging %d URLs.', $items);
80 public function ping($row)
86 $res = $this->pbc->send($from, $to);
87 } catch (\Exception $e) {
88 $this->log->err('Exception: ' . $e->getMessage());
90 'UPDATE feedentryurls SET'
92 . ', feu_updated = NOW()'
94 . ', feu_error_code = ' . $this->db->quote($e->getCode())
95 . ', feu_error_message = ' . $this->db->quote($e->getMessage())
96 . ', feu_tries = ' . $this->db->quote($row->feu_tries + 1)
97 . ', feu_retry = ' . $this->sqlRetry($e)
98 . ' WHERE feu_id = ' . $this->db->quote($row->feu_id)
103 if (!$res->isError()) {
105 $this->log->info('ok');
107 'UPDATE feedentryurls SET'
109 . ', feu_updated = NOW()'
111 . ', feu_error_code = ""'
112 . ', feu_error_message = ""'
113 . ', feu_tries = ' . $this->db->quote($row->feu_tries + 1)
115 . ' WHERE feu_id = ' . $this->db->quote($row->feu_id)
119 $this->log->err('Error: ' . $res->getCode() . ': ' . $res->getMessage());
120 $httpRes = $res->getResponse();
123 'Pingback response: Status code ' . $httpRes->getStatus()
124 . ', headers: ' . print_r($httpRes->getHeader(), true)
126 //. ', body: ' .$httpRes->getBody()
129 'UPDATE feedentryurls SET'
131 . ', feu_updated = NOW()'
133 . ', feu_error_code = ' . $this->db->quote($res->getCode())
134 . ', feu_error_message = ' . $this->db->quote($res->getMessage())
135 . ', feu_tries = ' . $this->db->quote($row->feu_tries + 1)
136 . ', feu_retry = ' . $this->sqlRetry($res)
137 . ' WHERE feu_id = ' . $this->db->quote($row->feu_id)
142 protected function sqlNeedsUpdate()
144 if ($this->deps->options['force']) {
147 $sqlRetry = '(feu_retry = 1 AND feu_tries < 5)';
148 //FIXME: wait at least 1 hour before retrying
150 return ' AND feu_active = 1 AND (feu_pinged = 0 OR ' . $sqlRetry . ')';
154 * Determines if it should be retried to pingback the URL after some time
156 * @param $obj mixed Exception or Pingback response
158 protected function sqlRetry($obj)
160 if ($obj instanceof \Exception) {
164 switch ($obj->getCode()) {
165 case -32601: //they have xmp-rpc, but do not support pingback
166 case 17: //they think we don't link to them
167 case 18: //they think we send out pingback spam
168 case 48: //already registered
169 case 49: //access denied
170 case 200: //pingback not supported
171 case 201: //Unvalid target URI