PHP code example of yuyat / parallel_http

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

    

yuyat / parallel_http example snippets



$urls = array(
    'http://twitter.com/',
    'http://www.facebook.com/',
    'http://www.yahoo.co.jp/',
    'http://www.google.co.jp/',
);

$loop   = new Yuyat_ParallelHttp_EventLoop;
$client = new Yuyat_ParallelHttp_Client($loop);

foreach ($urls as $url) {
    $request = $client->get($url, function ($response) {
        echo "Status Code: ";
        var_dump($response->getStatusCode());
        echo "Headers:", PHP_EOL;
        var_dump($response->getHeaders());
        echo "Body:", PHP_EOL;
        var_dump($response->getBody());
        echo PHP_EOL;
        echo PHP_EOL;
    });

    $request->on('error', function ($error) {
        echo "Error:", PHP_EOL;
        var_dump($error);
        echo PHP_EOL;
    });
}

$loop->run();