1. Go to this page and download the library: Download initphp/http library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
initphp / http example snippets
use InitPHP\HTTP\Facade\Factory;
use InitPHP\HTTP\Facade\Emitter;
$response = Factory::createResponse(200, 'OK')
->withHeader('Content-Type', 'text/plain; charset=utf-8');
$response->getBody()->write('Hello, world!');
Emitter::emit($response);
use InitPHP\HTTP\Client\Client;
use InitPHP\HTTP\Client\Retry\RetryPolicy;
$client = (new Client())->withRetryPolicy(new RetryPolicy(
maxAttempts: 4, // 1 initial try + up to 3 retries
baseDelay: 0.1, // first backoff interval, seconds
multiplier: 2.0, // 0.1s, 0.2s, 0.4s, ...
maxDelay: 30.0, // cap on any single interval
jitter: 0.5, // up to 50% random reduction (anti thundering-herd)
));
// Every verb helper inherits the policy transparently.
$response = $client->get('https://api.example.com/flaky');
// Customise: only retry 429/503, never on transport exceptions, ignore Retry-After.
new RetryPolicy(
maxAttempts: 5,
retryOnException: false,
retryableStatusCodes: [429, 503],
respectRetryAfter: false,
);
use InitPHP\HTTP\Emitter\Emitter;
$emitter = new Emitter(/* strictMode: */ true);
$emitter->emit($response); // echoes body in one go
// For large bodies, stream in chunks:
$emitter->emit($response, 8192);
use InitPHP\HTTP\Message\ServerRequest;
$request = ServerRequest::createFromGlobals();
// or with explicit data (recommended for tests and long-running runtimes):
$request = ServerRequest::createFromGlobals($server, $get, $post, $cookies, $files);
use InitPHP\HTTP\Facade\Factory;
use InitPHP\HTTP\Facade\Client;
use InitPHP\HTTP\Facade\Emitter;
$request = Factory::createRequest('GET', 'https://example.com');
$response = Client::sendRequest($request);
Emitter::emit($response);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.