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\Linkback\Client();
20 $req = $this->pbc->getRequest();
23 'ssl_verify_peer' => false,
24 'ssl_verify_host' => false
27 $this->pbc->setRequestTemplate($req);
28 $headers = $req->getHeaders();
29 $req->setHeader('user-agent', 'stapibas / ' . $headers['user-agent']);
31 $this->pbc->setDebug(true);
34 public function pingAll()
36 $this->log->info('Pinging all URLs..');
37 $res = $this->db->query(
38 'SELECT fe_url, feu_id, feu_url, feu_tries'
39 . ' FROM feedentries, feedentryurls'
40 . ' WHERE fe_id = feu_fe_id' . $this->sqlNeedsUpdate()
43 while ($row = $res->fetch(\PDO::FETCH_OBJ)) {
45 'Pinging URL #%d: %s', $row->feu_id, $row->feu_url
50 $this->log->info('Finished pinging %d URLs.', $items);
53 public function pingSome($urlOrIds)
56 foreach ($urlOrIds as $urlOrId) {
57 if (is_numeric($urlOrId)) {
58 $options[] = 'feu_id = ' . intval($urlOrId);
60 $options[] = 'feu_url = ' . $this->db->quote($urlOrId);
64 $this->log->info('Pinging %d URLs..', count($options));
65 $res = $this->db->query(
66 'SELECT fe_url, feu_id, feu_url, feu_tries'
67 . ' FROM feedentries, feedentryurls'
68 . ' WHERE fe_id = feu_fe_id'
69 . $this->sqlNeedsUpdate()
70 . ' AND (' . implode(' OR ', $options) . ')'
73 while ($row = $res->fetch(\PDO::FETCH_OBJ)) {
75 'Pinging URL #%d: %s', $row->feu_id, $row->feu_url
80 $this->log->info('Finished pinging %d URLs.', $items);
83 public function ping($row)
89 $res = $this->pbc->send($from, $to);
90 } catch (\Exception $e) {
91 $this->log->err('Exception: ' . $e->getMessage());
93 'UPDATE feedentryurls SET'
95 . ', feu_updated = NOW()'
97 . ', feu_error_code = ' . $this->db->quote($e->getCode())
98 . ', feu_error_message = ' . $this->db->quote($e->getMessage())
99 . ', feu_tries = ' . $this->db->quote($row->feu_tries + 1)
100 . ', feu_retry = ' . $this->sqlRetry($e)
101 . ' WHERE feu_id = ' . $this->db->quote($row->feu_id)
106 if (!$res->isError()) {
108 $this->log->info('ok');
110 'UPDATE feedentryurls SET'
112 . ', feu_updated = NOW()'
114 . ', feu_error_code = ""'
115 . ', feu_error_message = ""'
116 . ', feu_tries = ' . $this->db->quote($row->feu_tries + 1)
118 . ' WHERE feu_id = ' . $this->db->quote($row->feu_id)
122 $code = $res->getCode();
123 $this->log->err('Error: ' . $code . ': ' . $res->getMessage());
124 $httpRes = $res->getResponse();
127 'Pingback response: Status code ' . $httpRes->getStatus()
128 . ', headers: ' . print_r($httpRes->getHeader(), true)
130 if ($code == 100 || $code == 101 || $code == -32600) {
131 $this->log->info('HTTP body: ' . $httpRes->getBody());
135 'UPDATE feedentryurls SET'
137 . ', feu_updated = NOW()'
139 . ', feu_error_code = ' . $this->db->quote($res->getCode())
140 . ', feu_error_message = ' . $this->db->quote($res->getMessage())
141 . ', feu_tries = ' . $this->db->quote($row->feu_tries + 1)
142 . ', feu_retry = ' . $this->sqlRetry($res)
143 . ' WHERE feu_id = ' . $this->db->quote($row->feu_id)
148 protected function sqlNeedsUpdate()
150 if ($this->deps->options['force']) {
153 $sqlRetry = '(feu_retry = 1 AND feu_tries < 5)';
154 //FIXME: wait at least 1 hour before retrying
156 return ' AND feu_active = 1 AND (feu_pinged = 0 OR ' . $sqlRetry . ')';
160 * Determines if it should be retried to pingback the URL after some time
162 * @param $obj mixed Exception or Pingback response
164 protected function sqlRetry($obj)
166 if ($obj instanceof \Exception) {
170 switch ($obj->getCode()) {
171 case -32601: //they have xmp-rpc, but do not support pingback
172 case 17: //they think we don't link to them
173 case 18: //they think we send out pingback spam
174 case 48: //already registered
175 case 49: //access denied
176 case 200: //pingback not supported
177 case 201: //Unvalid target URI