PHP code example of perf / http-client

1. Go to this page and download the library: Download perf/http-client 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/ */

    

perf / http-client example snippets




use perf\HttpClient\HttpClient;

$httpClient = HttpClient::createDefault();

$request = $httpClient->createRequest();
$request
    ->methodGet()
    ->setUrl('http://localhost/index.html')
;

$response = $httpClient->execute($request);

$httpStatusCode = $response->getHttpStatusCode();
$content        = $response->getBodyContent();




use perf\HttpClient\HttpClient;

$httpClient = HttpClient::createDefault();

$request = $httpClient->createRequest();
$request
    ->methodPost(
        [
            'title'   => 'test article',
            'content' => 'article content ...',
            'photo'   => $httpClient->createFile('/path/to/file.jpg')
        ]
    )
    ->setUrl('http://localhost/create-article.php')
;

$response = $httpClient->execute($request);

$httpStatusCode = $response->getHttpStatusCode();
$content        = $response->getBodyContent();