PHP code example of pbergman / curl-multi

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

    

pbergman / curl-multi example snippets


use PBergman\CurlMulti\MultiHandler;
use PBergman\CurlMulti\Request;

$null = fopen("/dev/null", "w");
$handler = new MultiHandler(
    new Request([
        CURLOPT_URL => "http://httpstat.us/200?sleep=5000",
        CURLOPT_FILE  => $null,
    ]),
    new Request([
        CURLOPT_URL => "http://httpstat.us/404",
        CURLOPT_FILE  => $null,
    ])
);

try {
    foreach ($handler->getResponse() as $response) {
        printf(
            "request '%s' finished with code %d in %0.2fs\n",
            $response->getInfo(CURLINFO_EFFECTIVE_URL),
            $response->getInfo(CURLINFO_RESPONSE_CODE),
            $response->getInfo(CURLINFO_TOTAL_TIME)
        );
    }
} finally {
    // register cleanup
    $handler->close();
}