/** * 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; }
public static function critical($module_ = 'main', $data_ = '') { Logger::append($module_, $data_, 'critical'); }
if ($data->isUnderstood()) { break; } } // Allow testing in the url via ?ref=refs/heads/master. if (isset($_GET['branch'])) { $data->setBranch($_GET['branch']); } elseif (isset($_GET['ref'])) { $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: '******'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);
/** * 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); }