Installation and requirements
Cast installs with one Composer command and needs no configuration: you can send requests right after installing it.
Requirements
| What | Version | Why |
|---|---|---|
| PHP | ≥ 8.4 | readonly properties, new without parentheses in a chain |
ext-curl |
any recent one | the transport |
ext-swoole |
optional | coroutines: see Swoole |
HTTP/2 is used automatically when cURL is built with it and the server offers it. Without it, requests go over HTTP/1.1, and there is nothing to configure.
Installing
composer require flytachi/winter-castDependencies
| Package | Version | Why |
|---|---|---|
flytachi/winter-base |
^3.0 | HttpCode, Method |
psr/http-message |
^2.0 | PSR-7: requests, responses, streams |
psr/http-factory |
^1.1 | PSR-17: factories |
psr/http-client |
^1.0 | PSR-18: the client |
psr/log |
^3.0 | PSR-3: the client’s logger |
The package declares psr/http-client-implementation, psr/http-factory-implementation and
psr/http-message-implementation in provide. Libraries that need “some PSR-18 client”
therefore accept Cast without extra packages.
Checking it works
use Flytachi\Winter\Cast\Cast;
echo Cast::get('https://api.ipify.org', ['format' => 'json'])->send()->json()['ip'];If an IP address is printed, everything works.
Swoole
There is nothing to set up. In a Winter application the kernel itself enables
Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_ALL). If Swoole is built with curl-native,
cURL calls inside coroutines do not block the worker, and sendAll() runs requests on
coroutines. More in Transport and connection pool.
Outside Winter
In a Swoole server of your own, enable the hooks yourself before the first request:
\Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_ALL).