Skip to content

Instantly share code, notes, and snippets.

@lmammino
Last active August 29, 2015 13:57
Show Gist options
  • Save lmammino/9503406 to your computer and use it in GitHub Desktop.
Save lmammino/9503406 to your computer and use it in GitHub Desktop.
Multi curl tests for kriswallsmith/Buzz (ref: https://github.com/kriswallsmith/Buzz/issues/146)
{
"name": "example/multicurl",
"description": "a test with various multi curl libraries",
"require": {
"kriswallsmith/buzz": "dev-master",
"rdlowrey/artax": "dev-master",
"jyggen/curl": "dev-master"
},
"license": "MIT",
"authors": [
{
"name": "Luciano Mammino",
"email": "[email protected]"
}
]
}
curl
cURL support => enabled
cURL Information => 7.21.4
Age => 3
Features
AsynchDNS => No
CharConv => No
Debug => No
GSS-Negotiate => No
IDN => Yes
IPv6 => Yes
krb4 => No
Largefile => Yes
libz => Yes
NTLM => Yes
SPNEGO => No
SSL => Yes
SSPI => No
TLS-SRP => No
Protocols => dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtsp, smtp, smtps, telnet, tftp
Host => x86_64-apple-darwin12.2.0
SSL Version => OpenSSL/0.9.8y
ZLib Version => 1.2.5
curl
cURL support => enabled
cURL Information => 7.32.0
Age => 3
Features
AsynchDNS => Yes
CharConv => No
Debug => No
GSS-Negotiate => Yes
IDN => Yes
IPv6 => Yes
krb4 => No
Largefile => Yes
libz => Yes
NTLM => Yes
NTLMWB => Yes
SPNEGO => No
SSL => Yes
SSPI => No
TLS-SRP => Yes
Protocols => dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtmp, rtsp, smtp, smtps, telnet, tftp
Host => x86_64-pc-linux-gnu
SSL Version => OpenSSL/1.0.1e
ZLib Version => 1.2.8
<?php
require __DIR__ . '/vendor/autoload.php';
$requests = array(
'invalid' => 'http://invaliddomainxxxxx.com/',
'0' => 'https://gist.githubusercontent.com/lmammino/9135633/raw/9a4548bc93f308466c24b37a226ad416d8e27450/Uid.php',
'1' => 'https://gist.githubusercontent.com/lmammino/8730841/raw/2b90a317f828e875717809fc15349c2ca63090c7/gen_uuid.php',
'2' => 'https://gist.githubusercontent.com/lmammino/8467336/raw/89e500cfca87843446c7a468bda366200e1d01a4/dropbox',
'3' => 'https://gist.githubusercontent.com/lmammino/5309234/raw/9684a080fac2a84b79e22bafa75b6d2e7781481c/Gedit-Encrypt-document.sh',
'4' => 'https://gist.githubusercontent.com/lmammino/5309230/raw/ae2f26aaf34298065cc0adfcf3b66c16b85a8768/Gedit-Decrypt-document.sh',
);
$onResponse = function($requestKey, Artax\Response $response) {
echo 'Response: (', $requestKey, ') ', $response->getStatus(), "\n";
};
$onError = function($requestKey, Exception $error) {
echo 'Error: (', $requestKey, ') ', $error->getMessage(), "\n";
};
$client = new Artax\Client;
$client->requestMulti($requests, $onResponse, $onError);
<?php
require __DIR__ . '/vendor/autoload.php';
$requests = array(
'invalid' => new Buzz\Message\Request('get', 'http://invaliddomainxxxxx.com/'),
'0' => new Buzz\Message\Request('get', 'https://gist.githubusercontent.com/lmammino/9135633/raw/9a4548bc93f308466c24b37a226ad416d8e27450/Uid.php'),
'1' => new Buzz\Message\Request('get', 'https://gist.githubusercontent.com/lmammino/8730841/raw/2b90a317f828e875717809fc15349c2ca63090c7/gen_uuid.php'),
'2' => new Buzz\Message\Request('get', 'https://gist.githubusercontent.com/lmammino/8467336/raw/89e500cfca87843446c7a468bda366200e1d01a4/dropbox'),
'3' => new Buzz\Message\Request('get', 'https://gist.githubusercontent.com/lmammino/5309234/raw/9684a080fac2a84b79e22bafa75b6d2e7781481c/Gedit-Encrypt-document.sh'),
'4' => new Buzz\Message\Request('get', 'https://gist.githubusercontent.com/lmammino/5309230/raw/ae2f26aaf34298065cc0adfcf3b66c16b85a8768/Gedit-Decrypt-document.sh'),
);
$responses = array(
'invalid' => new Buzz\Message\Response(),
'0' => new Buzz\Message\Response(),
'1' => new Buzz\Message\Response(),
'2' => new Buzz\Message\Response(),
'3' => new Buzz\Message\Response(),
'4' => new Buzz\Message\Response(),
);
$client = new Buzz\Client\MultiCurl();
foreach ($requests as $requestKey => $request) {
$client->send($request, $responses[$requestKey]);
}
$client->flush();
/** @var Buzz\Message\Response $response */
foreach ($responses as $requestKey => $response) {
if ($response->isOk()) {
echo 'Response: (', $requestKey, ') ', $response->getStatusCode(), "\n";
} else {
echo 'Error: (', $requestKey, ') ', $response->getReasonPhrase(), "\n";
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
$requests = array(
'invalid' => new Jyggen\Curl\Request('http://invaliddomainxxxxx.com/'),
'0' => new Jyggen\Curl\Request('https://gist.githubusercontent.com/lmammino/9135633/raw/9a4548bc93f308466c24b37a226ad416d8e27450/Uid.php'),
'1' => new Jyggen\Curl\Request('https://gist.githubusercontent.com/lmammino/8730841/raw/2b90a317f828e875717809fc15349c2ca63090c7/gen_uuid.php'),
'2' => new Jyggen\Curl\Request('https://gist.githubusercontent.com/lmammino/8467336/raw/89e500cfca87843446c7a468bda366200e1d01a4/dropbox'),
'3' => new Jyggen\Curl\Request('https://gist.githubusercontent.com/lmammino/5309234/raw/9684a080fac2a84b79e22bafa75b6d2e7781481c/Gedit-Encrypt-document.sh'),
'4' => new Jyggen\Curl\Request('https://gist.githubusercontent.com/lmammino/5309230/raw/ae2f26aaf34298065cc0adfcf3b66c16b85a8768/Gedit-Decrypt-document.sh'),
);
$dispatcher = new Jyggen\Curl\Dispatcher();
foreach ($requests as $request) {
$dispatcher->add($request);
}
$dispatcher->execute();
/** @var Jyggen\Curl\Request $request */
foreach ($requests as $requestKey => $request) {
if ($request->isSuccessful()) {
echo 'Response: (', $requestKey, ') ', Symfony\Component\HttpFoundation\Response::$statusTexts[$request->getResponse()->getStatusCode()], "\n";
} else {
echo 'Error: (', $requestKey, ') ', $request->getErrorMessage(), "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment