Skip to main content
Version: Fegg 5.x

Client::__construct

Create a client with its timeouts

Description​

public Client::__construct( [ float $timeout = 10 [, float $connectTimeout = 3 [, ?string $transport = null ] ] ] )

The timeouts apply to every request made with this client.

Arguments​

NameData typeDefaultRemarks
$timeoutfloat10Seconds for the whole request
$connectTimeoutfloat3Seconds to connect (cURL only; the stream wrapper has the whole $timeout)
$transportstring|nullnull'curl' or 'stream'. null: cURL when the extension is installed, otherwise the stream wrapper. Set it only in tests

Example​

Controller
use Fegg\Http\Client;

$client = new Client(); // 10 seconds, 3 to connect
$quick = new Client(3, 1); // while a visitor waits for the page