PHP Classes

File: examples/02-headers.php

Recommend this page to a friend!
  Classes of Sergey Shuchkin  >  React PHP HTTP Client  >  examples/02-headers.php  >  Download  
File: examples/02-headers.php
Role: Example script
Content type: text/plain
Description: Example script
Class: React PHP HTTP Client
Process HTTP request responses asynchronously
Author: By
Last change:
Date: 2 years ago
Size: 717 bytes
 

Contents

Class file image Download
<?php

require_once __DIR__ . '/../vendor/autoload.php';

$loop = \React\EventLoop\Factory::create();

$http = new \Shuchkin\ReactHTTP\Client( $loop );
$http->request('GET', 'https://jigsaw.w3.org/HTTP/TE/foo.txt', null, ['User-Agent' => 'ReactPHP Awesome'] )->then(
    function ( \
Shuchkin\ReactHTTP\Client $client ) {

        echo
'HEADERS------------------------'.PHP_EOL;

       
/** @noinspection ForgottenDebugOutputInspection */
       
print_r( $client->headers );

        echo
PHP_EOL.'BODY-------------------------'
           
.PHP_EOL.$client->content;

        echo
PHP_EOL.'Content real length='.strlen( $client->content );

    },
    function ( \
Exception $ex ) {

        echo
'HTTP error '.$ex->getCode().' '.$ex->getMessage();

    }
);

$loop->run();

For more information send a message to info at phpclasses dot org.