Пример #1
0
 /**
  * Makes an HTTP request. This method can be overridden by subclasses if
  * developers want to do fancier things or use something other than curl to
  * make the request.
  *
  * @param string $url The URL to make the request to
  * @param array $params The parameters to use for the POST body
  * @param CurlHandler $ch Initialized curl handle
  *
  * @return string The response text
  */
 protected function makeRequest($url, $params, $ch = null)
 {
     $options = \BaseFacebook::$CURL_OPTS;
     $options[CURLOPT_URL] = $url;
     if ($this->getFileUploadSupport()) {
         $options[CURLOPT_POSTFIELDS] = $params;
     } else {
         $options[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
     }
     $start = microtime(true);
     $request = new Curl($options);
     $result = $request->getContent();
     $this->logger->append($url, array('params' => $params, 'duration' => microtime(true) - $start));
     return $result;
 }
Пример #2
0
 public static function critical($module_ = 'main', $data_ = '')
 {
     Logger::append($module_, $data_, 'critical');
 }
Пример #3
0
        $data->setBranch($_GET['ref']);
    }
    if (isset($_GET['repo'])) {
        $data->setRepoName($_GET['repo']);
    }
    $config = new Config($conf);
    $config->setBranch($data->getBranch())->setName($data->getRepoName());
    $log->append('origin user: ' . $data->getUsername());
    $log->append('repo: ' . $data->getRepoName());
    $log->append('branch: ' . $data->getBranch());
    $total_added = 0;
    if (!($jobs = $conf['jobber']->getJobsFileHandle('a'))) {
        $log->append('Invalid log configuration.');
    } elseif ($jobs && ($commands = $config->getJobs())) {
        foreach ($commands as $cmd) {
            fwrite($jobs, $cmd . PHP_EOL);
            $log->header();
            ++$total_added;
        }
    }
    fclose($jobs);
    if ($total_added) {
        $log->append('jobs added: ' . $total_added);
    }
} else {
    header("HTTP/1.0 401 Access Denied");
    $log->append('401: Access Denied');
}
$log->close();
header("Content Type: text/html");
print '<p>' . $log->view("</p>\n</p>") . '</p>' . PHP_EOL;
Пример #4
0
 /**
  * Perform the requests.
  */
 public function performRequests()
 {
     // Are there requests to perform?
     if (empty($this->requests)) {
         return;
     }
     // Add the handles.
     foreach ($this->requests as $request) {
         if (!$request->fromCache) {
             curl_multi_add_handle($this->handler, $request->curl);
         }
     }
     // Perform the requests.
     $running = null;
     do {
         curl_multi_exec($this->handler, $running);
     } while ($running);
     // Close handlers
     foreach ($this->requests as $request) {
         if (!$request->fromCache) {
             curl_multi_remove_handle($this->handler, $request->curl);
         }
     }
     // Loop through requests, process curl data.
     foreach ($this->requests as $request) {
         // Skip cached items
         if ($request->fromCache) {
             continue;
         }
         $result = curl_multi_getcontent($request->curl);
         $info = curl_getinfo($request->curl);
         $errorMessage = curl_error($request->curl);
         $errorNumber = curl_errno($request->curl);
         $request->response = new Response($result, $info, $errorMessage, $errorNumber);
         $log = "[Code: {$request->response->httpCode}] [Async] {$request->method} {$request->baseUrl}";
         // Is the response body an array?
         if (is_array($request->response->body)) {
             // Are there 50 items?
             $numItems = count($request->response->body);
             if (50 == $numItems) {
                 // Add or bump 'page' parameter.
                 $request->args['page'] = isset($request->args['page']) ? $request->args['page'] + 1 : 2;
                 // Perform a do ... while loop, creating subsequent page requests so long as
                 // the page isn't empty.
                 do {
                     // Make a new request.
                     $newRequest = new Request($request->baseUrl, $request->args, $request->method);
                     $newRequest->performRequest();
                     $request->args['page']++;
                     $numItems = count($newRequest->response->body);
                     // If there are items in the new request, then we want to merge them into
                     // the main body.
                     if ($numItems > 0) {
                         $request->response->body = array_merge($request->response->body, $newRequest->response->body);
                     }
                 } while ($numItems != 0 && $numItems == 50);
             }
         }
         Logger::append($log);
     }
     // Close multi curl.
     curl_multi_close($this->handler);
 }