예제 #1
0
 * @license http://sabre.io/license/ Modified BSD License
 */
use Sabre\HTTP\Request, Sabre\HTTP\Client;
// Find the autoloader
$paths = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php', __DIR__ . '/vendor/autoload.php'];
foreach ($paths as $path) {
    if (file_exists($path)) {
        include $path;
        break;
    }
}
// This is the request we're repeating a 1000 times.
$request = new Request('GET', 'http://localhost/');
$client = new Client();
for ($i = 0; $i < 1000; $i++) {
    echo "{$i} sending\n";
    $client->sendAsync($request, function ($response) use($i) {
        echo "{$i} -> " . $response->getStatus() . "\n";
    }, function ($error) use($i) {
        if ($error['status'] === Client::STATUS_CURLERROR) {
            // Curl errors
            echo "{$i} -> curl error: " . $error['curl_errmsg'] . "\n";
        } else {
            // HTTP errors
            echo "{$i} -> " . $error['response']->getStatus() . "\n";
        }
    });
}
// After everything is done, we call 'wait'. This causes the client to wait for
// all outstanding http requests to complete.
$client->wait();