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, feu_tries'
65 . ' FROM feedentries, feedentryurls'
66 . ' WHERE fe_id = feu_fe_id'
67 . $this->sqlNeedsUpdate()
68 . ' AND (' . implode(' OR ', $options) . ')'
71 while ($row = $res->fetch(\PDO::FETCH_OBJ)) {
73 'Pinging URL #%d: %s', $row->feu_id, $row->feu_url
78 $this->log->info('Finished pinging %d URLs.', $items);
81 public function ping($row)
87 $res = $this->pbc->send($from, $to);
88 } catch (\Exception $e) {
89 $this->log->err('Exception: ' . $e->getMessage());
91 'UPDATE feedentryurls SET'
93 . ', feu_updated = NOW()'
95 . ', feu_error_code = ' . $this->db->quote($e->getCode())
96 . ', feu_error_message = ' . $this->db->quote($e->getMessage())
97 . ', feu_tries = ' . $this->db->quote($row->feu_tries + 1)
98 . ', feu_retry = ' . $this->sqlRetry($e)
99 . ' WHERE feu_id = ' . $this->db->quote($row->feu_id)
104 if (!$res->isError()) {
106 $this->log->info('ok');
108 'UPDATE feedentryurls SET'
110 . ', feu_updated = NOW()'
112 . ', feu_error_code = ""'
113 . ', feu_error_message = ""'
114 . ', feu_tries = ' . $this->db->quote($row->feu_tries + 1)
116 . ' WHERE feu_id = ' . $this->db->quote($row->feu_id)
120 $code = $res->getCode();
121 $this->log->err('Error: ' . $code . ': ' . $res->getMessage());
122 $httpRes = $res->getResponse();
125 'Pingback response: Status code ' . $httpRes->getStatus()
126 . ', headers: ' . print_r($httpRes->getHeader(), true)
128 if ($code == 100 || $code == 101 || $code == -32600) {
129 $this->log->info('HTTP body: ' . $httpRes->getBody());
133 'UPDATE feedentryurls SET'
135 . ', feu_updated = NOW()'
137 . ', feu_error_code = ' . $this->db->quote($res->getCode())
138 . ', feu_error_message = ' . $this->db->quote($res->getMessage())
139 . ', feu_tries = ' . $this->db->quote($row->feu_tries + 1)
140 . ', feu_retry = ' . $this->sqlRetry($res)
141 . ' WHERE feu_id = ' . $this->db->quote($row->feu_id)
146 protected function sqlNeedsUpdate()
148 if ($this->deps->options['force']) {
151 $sqlRetry = '(feu_retry = 1 AND feu_tries < 5)';
152 //FIXME: wait at least 1 hour before retrying
154 return ' AND feu_active = 1 AND (feu_pinged = 0 OR ' . $sqlRetry . ')';
158 * Determines if it should be retried to pingback the URL after some time
160 * @param $obj mixed Exception or Pingback response
162 protected function sqlRetry($obj)
164 if ($obj instanceof \Exception) {
168 switch ($obj->getCode()) {
169 case -32601: //they have xmp-rpc, but do not support pingback
170 case 17: //they think we don't link to them
171 case 18: //they think we send out pingback spam
172 case 48: //already registered
173 case 49: //access denied
174 case 200: //pingback not supported
175 case 201: //Unvalid target URI