示例#1
0
文件: Daemon.php 项目: zource/zource
 public function run()
 {
     $endTime = time() + $this->lifetime;
     $this->logger->info(sprintf('Started listening with a lifetime of %d seconds.', $this->lifetime));
     while (time() < $endTime) {
         try {
             /** @var \Pheanstalk\Job $job */
             $job = $this->pheanstalk->reserve(1);
         } catch (Exception $exception) {
         }
         if ($job) {
             $this->logger->info(sprintf('Reserved job #%d: %s', $job->getId(), $job->getData()));
             try {
                 $data = json_decode($job->getData(), true);
                 /** @var WorkerInterface $worker */
                 $worker = $this->workerManager->get($data['worker'], $data['params']);
                 $worker->run(new Context($this, $this->logger, $data['params']));
                 $this->logger->info(sprintf('Finished job #%d', $job->getId()));
                 $this->pheanstalk->delete($job);
             } catch (Exception $exception) {
                 $this->logger->emerg('Failed to execute job #' . $job->getId(), ['exception' => $exception]);
                 $this->pheanstalk->bury($job);
             }
         }
         usleep($this->interval);
     }
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function report($priority, $message, $extra = [])
 {
     if ($this->log === null) {
         return;
     }
     switch ($priority) {
         case Logger::EMERG:
             $this->log->emerg($message, $extra);
             break;
         case Logger::ERR:
             $this->log->err($message, $extra);
             break;
         default:
             break;
     }
 }
 /**
  * (non-PHPdoc)
  *
  * @see \ZendGoogleGeocoder\Service\GeocoderApiInterface::fetchGeoDataForAddress()
  */
 public function fetchGeoDataForAddress($address, $format = null)
 {
     if (null !== $format) {
         $this->validateFormat($format);
     } else {
         $format = $this->getDefaultFormat();
     }
     $this->logger->debug(sprintf('Generating URL for requesting the Google Geocoder API with format: %s', $format));
     $url = $this->generateRequestUrl($address, $format);
     if (true === $this->hasStreamSupport()) {
         // Use file_get_contents. It's faster, but not supported by every shared hoster.
         $this->logger->debug(sprintf('allow_url_fopen is enabled. Using file_get_contents to retrieve response.'));
         return $this->doStreamRequest($url, $format);
     } elseif (true === $this->hasCurlSupport()) {
         // Use curl. A bit overkill, but works fine.
         $this->logger->debug(sprintf('Using cURL to retrieve response.'));
         return $this->doCurlRequest($url, $format);
     } else {
         $this->logger->emerg('Unable to fire a HTTP-Request to the Google Geocoder API, since wether "allow_url_fopen" is enabled nor the mod_curl is installed.');
         throw new \Exception('Unable to fire a HTTP-Request to the Google Geocoder API, since wether "allow_url_fopen" is enabled nor the mod_curl is installed.', 200);
     }
 }