From: Christian Weiske Date: Thu, 13 Jun 2013 22:49:43 +0000 (+0200) Subject: code to send pingbacks to all urls X-Git-Url: https://git.cweiske.de/stapibas.git/commitdiff_plain/59a7003c47ae1f670ae6d779e9e7f124b1dc5b01?ds=sidebyside code to send pingbacks to all urls --- diff --git a/bin/stapibas b/bin/stapibas index 5c24009..cecbcb9 100755 --- a/bin/stapibas +++ b/bin/stapibas @@ -17,4 +17,9 @@ $uf->db = $db; $uf->log = $log; $uf->updateAll(); +$uf = new Feed_PingUrls(); +$uf->db = $db; +$uf->log = $log; +$uf->pingAll(); + ?> diff --git a/src/stapibas/Feed/PingUrls.php b/src/stapibas/Feed/PingUrls.php new file mode 100644 index 0000000..17fff79 --- /dev/null +++ b/src/stapibas/Feed/PingUrls.php @@ -0,0 +1,94 @@ +pbc = new \PEAR2\Services\Pingback\Client(); + + $req = new \HTTP_Request2(); + $req->setConfig( + array( + 'ssl_verify_peer' => false, + 'ssl_verify_host' => false + ) + ); + $this->pbc->setRequest($req); + $this->pbc->setDebug(true); + } + + public function pingAll() + { + $this->log->info('Pinging all URLs..'); + $res = $this->db->query( + 'SELECT fe_url, feu_id, feu_url FROM feedentries, feedentryurls' + . ' WHERE fe_id = feu_fe_id AND feu_active = 1 AND feu_pinged = 0' + ); + $items = 0; + while ($row = $res->fetch(\PDO::FETCH_OBJ)) { + $this->log->info( + sprintf('Pinging URL #%d: %s', $row->feu_id, $row->feu_url) + ); + $this->ping($row); + ++$items; + } + $this->log->info(sprintf('Finished pinging %d URLs.', $items)); + } + + public function ping($row) + { + $from = $row->fe_url; + $to = $row->feu_url; + + try { + $res = $this->pbc->send($from, $to); + } catch (\Exception $e) { + $this->log->err('Exception: ' . $e->getMessage()); + $this->db->exec( + 'UPDATE feedentryurls SET' + . ' feu_pinged = 1' + . ', feu_updated = NOW()' + . ', feu_error = ' . $this->db->quote($e->getMessage()) + . ' WHERE feu_id = ' . $this->db->quote($row->feu_id) + ); + return; + } + + if (!$res->isError()) { + //all fine + $this->log->info('ok'); + $this->db->exec( + 'UPDATE feedentryurls SET' + . ' feu_pinged = 1' + . ', feu_updated = NOW()' + . ', feu_error = ""' + . ' WHERE feu_id = ' . $this->db->quote($row->feu_id) + ); + } else { + //error + $this->log->err('Error: ' . $res->getCode() . ': ' . $res->getMessage()); + $this->log->info( + 'Pingback response: Status code ' . $res->getResponse()->getStatus() + . ', headers: ' . print_r($res->getResponse()->getHeader(), true) + . ', body: ' . $res->getResponse()->getBody() + ); + $this->db->exec( + 'UPDATE feedentryurls SET' + . ' feu_pinged = 1' + . ', feu_updated = NOW()' + . ', feu_error = ' + . $this->db->quote($res->getCode() . ': ' . $res->getMessage()) + . ' WHERE feu_id = ' . $this->db->quote($row->feu_id) + ); + } + } +} +?>