public function handle(Request $request, Response $response) { $headers = array_change_key_case($request->getHeaders(), CASE_LOWER); // Only enable when the X-Blackfire-Query header is present if (!isset($headers['x-blackfire-query'])) { return array(); } $probe = new \BlackfireProbe($headers['x-blackfire-query']); // Stop if it failed if (!$probe->enable()) { return array(); } // Stop profiling once the request ends $response->on('end', array($probe, 'close')); // Return the header $header = explode(':', $probe->getResponseLine(), 2); return array('x-' . $header[0] => $header[1]); }