/** * Overrides default Guzzle usage of curl_multi_exec by a simple curl call * and adds some metrics in Newrelic * * @param EntityEnclosingRequest $request * @return Response */ public static function sendRequest( EntityEnclosingRequest $request ) { $ch = curl_init($request->getUrl()); $curlOptions = array( CURLOPT_URL => $request->getUrl(), CURLOPT_TIMEOUT => \eZINI::instance('merck.ini')->variable('WebService', 'ESBTimeout'), CURLOPT_CONNECTTIMEOUT => \eZINI::instance('merck.ini')->variable('WebService', 'ESBConnectTimeout'), CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_USERAGENT => (string) $request->getHeader('User-Agent'), CURLOPT_PORT => $request->getPort(), CURLOPT_HTTPHEADER => $request->getHeaderLines(), CURLOPT_HTTP_VERSION => $request->getProtocolVersion() === '1.0' ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1, // Verifies the authenticity of the peer's certificate CURLOPT_SSL_VERIFYPEER => 1, // Certificate must indicate that the server is the server to which you meant to connect CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_POST => true, CURLOPT_POSTFIELDS => (string) $request->getBody(), CURLOPT_VERBOSE => false, ); curl_setopt_array($ch, $curlOptions); $start = microtime(true); $curlResult = curl_exec( $ch ); $curlCallTime = ( microtime(true) - $start ) * 1000; $newRelicApi = new \klpNrApi(); $methodLabel = preg_match('#/(?P<method>[^/?]+)(?:\?.*)?$#', $request->getUrl(), $m) ? ucfirst( $m['method'] ) : 'Unknown'; $newRelicApi->addParameter( 'ESB/'.$methodLabel.':'.$request->getPort(), $curlCallTime ); $newRelicApi->setCustomMetric( 'Custom/ESB/'.$methodLabel, $curlCallTime ); $body = $curlResult; $maxHeaderBlocks = 5; $index = 0; // We have to deal with HTTP/1.1 100 continue headers do { list( $header, $body ) = explode("\r\n\r\n", $body, 2); $index++; } while( $index < $maxHeaderBlocks && strpos($body, 'HTTP/1') === 0 ); $parsedHeaders = array(); foreach( explode("\n", $header) as $h ) { list( $key, $val ) = explode(':', $h); $parsedHeaders[trim($key)] = trim($val); } $http_status = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); if ( \eZINI::instance('merck.ini')->variable( 'WebService', 'CurlGetInfo' ) == 'enabled' ) { $curlInfo = curl_getinfo($ch); $logMessage = \ClusterTool::clusterIdentifier().'::'.$methodLabel."\n"; $logMessage .= var_export( $curlInfo, true ); \eZLog::write($logMessage, 'esbcurldetails.log'); } curl_close($ch); $response = new Response( $http_status, $parsedHeaders, $body ); $response->setRequest($request); $request->setResponse($response); return $response; }