本文整理汇总了PHP中Guzzle\Http\Message\Response::getInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getInfo方法的具体用法?PHP Response::getInfo怎么用?PHP Response::getInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Response
的用法示例。
在下文中一共展示了Response::getInfo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: logResponse
/**
* @param \Guzzle\Http\Message\Response $response
* @param array $extra
*/
public function logResponse($response, $extra = array())
{
!array_key_exists("serialization_time", $extra) && ($extra["serialization_time"] = "-");
!array_key_exists("deserialization_time", $extra) && ($extra["deserialization_time"] = "-");
!array_key_exists("search_time", $extra) && ($extra["search_time"] = "-");
!array_key_exists("method", $extra) && ($extra["method"] = "-");
$this->logger->debug(self::getProcessId() . ' ' . $extra["method"] . ' ' . $response->getInfo("url") . ' ' . $response->getInfo("total_time") . ' ' . $extra["deserialization_time"] . ' ' . $extra["serialization_time"] . ' ' . $extra["search_time"]);
}
示例2: getPriorityFromResponse
/**
* @param Response $response
* @return int
*/
private function getPriorityFromResponse(Response $response)
{
if ($response->isServerError() || $response->getInfo('total_time') > 5) {
return Logger::ERROR;
}
if ($response->isClientError() || $response->getInfo('total_time') > 1) {
return Logger::WARNING;
}
return Logger::INFO;
}
示例3: getRequestTime
private function getRequestTime(GuzzleResponse $response)
{
$time = $response->getInfo('total_time');
if (null === $time) {
$time = 0;
}
return (int) ($time * 1000);
}
示例4: getContextFromResponse
private function getContextFromResponse(Response $response)
{
$extraFields = array();
$headersToLookFor = array('x-served-by', 'x-backend', 'x-location', 'x-varnish');
foreach ($headersToLookFor as $headerName) {
if ($response->hasHeader($headerName)) {
$extraFields[$headerName] = (string) $response->getHeader($headerName);
}
}
$extraFields['responseTime'] = $response->getInfo('total_time');
return $extraFields;
}
示例5: format
/**
* Returns a formatted message
*
* @param RequestInterface $request Request that was sent
* @param Response $response Response that was received
* @param CurlHandle $handle Curl handle associated with the message
* @param array $customData Associative array of custom template data
*
* @return string
*/
public function format(RequestInterface $request, Response $response = null, CurlHandle $handle = null, array $customData = array())
{
$cache = $customData;
return preg_replace_callback('/{\\s*([A-Za-z_\\-\\.0-9]+)\\s*}/', function (array $matches) use($request, $response, $handle, &$cache) {
if (array_key_exists($matches[1], $cache)) {
return $cache[$matches[1]];
}
$result = '';
switch ($matches[1]) {
case 'request':
$result = (string) $request;
break;
case 'response':
$result = (string) $response;
break;
case 'req_body':
$result = $request instanceof EntityEnclosingRequestInterface ? (string) $request->getBody() : '';
break;
case 'res_body':
$result = $response ? $response->getBody(true) : '';
break;
case 'ts':
$result = gmdate('c');
break;
case 'method':
$result = $request->getMethod();
break;
case 'url':
$result = (string) $request->getUrl();
break;
case 'resource':
$result = $request->getResource();
break;
case 'protocol':
$result = 'HTTP';
break;
case 'version':
$result = $request->getProtocolVersion();
break;
case 'host':
$result = $request->getHost();
break;
case 'hostname':
$result = gethostname();
break;
case 'port':
$result = $request->getPort();
break;
case 'code':
$result = $response ? $response->getStatusCode() : '';
break;
case 'phrase':
$result = $response ? $response->getReasonPhrase() : '';
break;
case 'connect_time':
if ($handle) {
$result = $handle->getInfo(CURLINFO_CONNECT_TIME);
} elseif ($response) {
$result = $response->getInfo('connect_time');
}
break;
case 'total_time':
if ($handle) {
$result = $handle->getInfo(CURLINFO_TOTAL_TIME);
} elseif ($response) {
$result = $response->getInfo('total_time');
}
break;
case 'curl_error':
$result = $handle ? $handle->getError() : '';
break;
case 'curl_code':
$result = $handle ? $handle->getErrorNo() : '';
break;
case 'curl_stderr':
$result = $handle ? $handle->getStderr() : '';
break;
default:
if (strpos($matches[1], 'req_header_') === 0) {
$result = $request->getHeader(substr($matches[1], 11));
} elseif (strpos($matches[1], 'res_header_') === 0) {
$result = $response->getHeader(substr($matches[1], 11));
}
}
$cache[$matches[1]] = $result;
return $result;
}, $this->template);
}
示例6: log
/**
* Log a message based on a request and response
*
* @param RequestInterface $request Request to log
* @param Response $response Response to log
*/
private function log(RequestInterface $request, Response $response = null)
{
$message = '';
if ($this->settings & self::LOG_CONTEXT) {
// Log common contextual information
$message = $request->getHost() . ' - "' . $request->getMethod() . ' ' . $request->getResource() . ' ' . strtoupper($request->getScheme()) . '/' . $request->getProtocolVersion() . '"';
// If a response is set, then log additional contextual information
if ($response) {
$message .= sprintf(' - %s %s - %s %s %s', $response->getStatusCode(), $response->getContentLength() ?: 0, $response->getInfo('total_time'), $response->getInfo('speed_upload'), $response->getInfo('speed_download'));
}
}
// Check if we are logging anything that will come from cURL
if ($request->getParams()->get('curl_handle') && ($this->settings & self::LOG_DEBUG || $this->settings & self::LOG_HEADERS || $this->settings & self::LOG_BODY)) {
// If context logging too, then add a new line for cleaner messages
if ($this->settings & self::LOG_CONTEXT) {
$message .= "\n";
}
// Filter cURL's verbose output based on config settings
$message .= $this->parseCurlLog($request);
// Log the response body if the response is available
if ($this->settings & self::LOG_BODY && $response) {
if ($request->getParams()->get('response_wire')) {
$message .= (string) $request->getParams()->get('response_wire');
} else {
$message .= $response->getBody(true);
}
}
}
// Send the log message to the adapter, adding a category and host
$priority = $response && !$response->isSuccessful() ? LOG_ERR : LOG_DEBUG;
$this->logAdapter->log(trim($message), $priority, array('category' => 'guzzle.request', 'host' => $this->hostname));
}