/**
  * JSON文字列を配列に変換
  *
  * @param string $json 変換するJSON形式の文字列
  * @return mix エラー時null値
  */
 public function convert($json)
 {
     if (is_null($arrayData = json_decode($json, true))) {
         $this->log->warning('JSONへの変換エラー(' . $this->getJsonLastError() . ')');
     }
     return $arrayData;
 }
 /**
  * Called when the crawl has ended.
  */
 public function finishedCrawling()
 {
     $this->log->info('link checker summary');
     collect($this->urlsGroupedByStatusCode)->each(function ($urls, $statusCode) {
         if ($this->isSuccessOrRedirect($statusCode)) {
             return;
         }
         $count = count($urls);
         if ($statusCode == static::UNRESPONSIVE_HOST) {
             $this->log->warning("{$count} url(s) did have unresponsive host(s)");
             return;
         }
         $this->log->warning("Crawled {$count} url(s) with statuscode {$statusCode}");
     });
 }
 public function get($url, $header = [])
 {
     // curlで接続
     $curl = curl_init($url);
     // オプション指定
     $options = [CURLOPT_HTTPHEADER => $header, CURLOPT_RETURNTRANSFER => true];
     curl_setopt_array($curl, $options);
     // 呼び出し
     $result = curl_exec($curl);
     $info = curl_getinfo($curl);
     curl_close($curl);
     if ($result === false || $info['http_code'] != 200) {
         $this->log->warning('通信できませんでした。URL:' . $url . ' Code:' . $info['http_code']);
         return false;
     }
     return $result;
 }
 public function put($url, $data = [])
 {
     // curlで接続
     $curl = curl_init($url);
     // オプションとデーター指定
     $options = [CURLOPT_HTTPHEADER => ['Content-type: application/json'], CURLOPT_PUT => true, CURLOPT_POSTFIELDS => json_encode($data), CURLOPT_RETURNTRANSFER => true];
     curl_setopt_array($curl, $options);
     // 呼び出し
     $result = curl_exec($curl);
     $info = curl_getinfo($curl);
     curl_close($curl);
     if ($result === false || $info['http_code'] != 200) {
         $this->log->warning('PUT通信できませんでした。URL:' . $url . ' Code:' . $info['http_code']);
         return false;
     }
     return $result;
 }
 public function __invoke(array $data) : array
 {
     foreach ($data['prepared'] as $key => $value) {
         try {
             $json = json_decode((string) $this->request($value['data'])->getBody(), true);
             $searchId = $json['search_id'];
             unset($json);
             $data['ongoing'][$key] = $value;
             $data['ongoing'][$key]['data'] = $searchId;
             unset($data['prepared'][$key]);
             $this->log->debug('Count has begun', ['date' => $key, 'searchId' => $searchId]);
         } catch (RequestException $e) {
             /**
              * This may happen. Just skip that query and move on.
              */
             $this->log->warning('Count failed to begin', ['message' => $e->getMessage(), 'date' => $key, 'searchId' => $searchId]);
         }
     }
     return $data;
 }
Exemplo n.º 6
0
 /**
  * Execute the job
  *
  * @param Log $log
  * @return void
  */
 public function handle(Log $log)
 {
     $log->debug("Handling check job for queue '{$this->queueName}', queued at {$this->startTime}");
     $status = QueueStatus::get($this->queueName);
     if (!$status) {
         $message = "Queue status was not found in cache, yet queued job ran; is the cache correctly configured?";
         $log->error($message);
         $status = new QueueStatus($this->queueName, QueueStatus::ERROR, false);
         $status->setMessage($message);
         $status->setEndTime();
         $status->save();
     } elseif (!$status->isPending()) {
         $log->warning("Non-pending status for check for queue '{$this->queueName}' found in the cache; ignoring: " . $status);
     } elseif (!$status->getStartTime() || $status->getStartTime()->ne($this->startTime)) {
         $log->warning("Pending status for check for queue '{$this->queueName}' found in the cache with mismatching time (expected {$this->startTime}, found {$status->getStartTime()}); ignoring: " . $status);
     } else {
         $log->debug("Successful queue check for queue '{$this->queueName}'");
         $status->setStatus(QueueStatus::OK);
         $status->setEndTime();
         $status->save();
     }
 }