public function testStreamingCallsStreamingHandler() { $calledA = false; $a = function (array $req) use(&$calledA) { $calledA = true; }; $calledB = false; $b = function (array $req) use(&$calledB) { $calledB = true; }; $s = Middleware::wrapStreaming($a, $b); $s(['client' => ['stream' => true]]); $this->assertFalse($calledA); $this->assertTrue($calledB); }
/** * Create a default handler to use based on the environment * * @throws \RuntimeException if no viable Handler is available. */ public static function getDefaultHandler() { $default = $future = $streaming = null; if (extension_loaded('curl')) { $config = array('select_timeout' => getenv('GUZZLE_CURL_SELECT_TIMEOUT') ?: 1); if ($maxHandles = getenv('GUZZLE_CURL_MAX_HANDLES')) { $config['max_handles'] = $maxHandles; } $future = new CurlMultiHandler($config); if (function_exists('curl_reset')) { $default = new CurlHandler(); } } if (ini_get('allow_url_fopen')) { $streaming = new StreamHandler(); } if (!($default = $default ?: $future ?: $streaming)) { throw new \RuntimeException('Guzzle requires cURL, the ' . 'allow_url_fopen ini setting, or a custom HTTP handler.'); } $handler = $default; if ($streaming && $streaming !== $default) { $handler = Middleware::wrapStreaming($default, $streaming); } if ($future) { $handler = Middleware::wrapFuture($handler, $future); } return $handler; }
/** * Create a default handler to use based on the environment * * @throws \RuntimeException if no viable Handler is available. */ public static function getDefaultHandler() { $default = $future = null; if (extension_loaded('curl')) { $config = ['select_timeout' => getenv('GUZZLE_CURL_SELECT_TIMEOUT') ?: 1]; if ($maxHandles = getenv('GUZZLE_CURL_MAX_HANDLES')) { $config['max_handles'] = $maxHandles; } if (function_exists('curl_reset')) { $default = new CurlHandler(); $future = new CurlMultiHandler($config); } else { $default = new CurlMultiHandler($config); } } if (ini_get('allow_url_fopen')) { $default = !$default ? new StreamHandler() : Middleware::wrapStreaming($default, new StreamHandler()); } elseif (!$default) { throw new \RuntimeException('Guzzle requires cURL, the ' . 'allow_url_fopen ini setting, or a custom HTTP handler.'); } return $future ? Middleware::wrapFuture($default, $future) : $default; }