Issues (7)

examples/quickstart.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * @codingStandardsIgnoreStart
4
 *
5
 * @author       Barney Hanlon <[email protected]>
6
 * @copyright    Barney Hanlon 2017
7
 * @license      https://opensource.org/licenses/MIT
8
 *
9
 * @codingStandardsIgnoreEnd
10
 */
11
12
use GuzzleHttp\Client;
13
use GuzzleHttp\HandlerStack;
14
use GuzzleHttp\Promise;
15
use Monolog\Handler\StreamHandler;
16
use Monolog\Logger;
17
use Shrikeh\GuzzleMiddleware\TimerLogger\Middleware;
18
19
require_once __DIR__.'/../vendor/autoload.php';
20
21
$logsPath = __DIR__.'/logs';
22
if (!is_dir($logsPath)) {
23
    mkdir($logsPath);
24
}
25
26
$logFile = new SplFileObject($logsPath.'/example.log', 'w+');
27
28
// create a log channel
29
$log = new Logger('guzzle');
30
$log->pushHandler(new StreamHandler(
31
    $logFile->getRealPath(),
32
    Logger::DEBUG
33
));
34
35
// hand it to the middleware (this will create a default working example)
36
$middleware = Middleware::quickStart($log);
37
38
// now create a Guzzle middleware stack
39
$stack = HandlerStack::create();
40
41
// and register the middleware on the stack
42
$stack->push($middleware());
43
44
$config = [
45
    'timeout'   => 2,
46
    'handler' => $stack,
47
];
48
49
// then hand the stack to the client
50
$client = new Client($config);
51
52
$promises = [
53
    'facebook'  => $client->getAsync('https://www.facebook.com'),
54
    'wikipedia' => $client->getAsync('https://en.wikipedia.org/wiki/Main_Page'),
55
    'google'    => $client->getAsync('https://www.google.co.uk'),
56
];
57
58
$results = Promise\settle($promises)->wait();
0 ignored issues
show
The function settle was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
$results = /** @scrutinizer ignore-call */ Promise\settle($promises)->wait();
Loading history...
59
60
print $logFile->fread($logFile->getSize());
61