Пример #1
0
 public function getInfo($key, $default = null)
 {
     syslog(LOG_INFO, "getting info for key {$key} on request " . $_SERVER['REQUEST_URI']);
     if (empty($this->info)) {
         $this->info = array();
         syslog(LOG_INFO, 'guzzle start for url ' . $this->url);
         $guzzle = new GuzzleClient($this->url);
         $guzzle->getEventDispatcher()->addListener('request.error', function (Event $event) {
             $event->stopPropagation();
         });
         $response = $guzzle->head()->send();
         if (!$response->isSuccessful()) {
             $response = $guzzle->get()->send();
         }
         if ($response->isSuccessful()) {
             $this->info = $response->getInfo();
         }
         syslog(LOG_INFO, 'guzzle stop for url ' . $this->url);
     }
     return isset($this->info[$key]) ? $this->info[$key] : $default;
 }