forked from hungvietdo/log-access-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload-access-log.php
More file actions
33 lines (23 loc) · 915 Bytes
/
Copy pathload-access-log.php
File metadata and controls
33 lines (23 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
require_once __DIR__ . '/vendor/autoload.php';
$parser = new \Kassner\LogParser\LogParser();
$accesslogFile = 'www.equipmenttrader.com.access.log';
$base_uri = 'http://cloud.equip.local';
$parser->setFormat('%h %v %u %a - - - - - %t "%r" %>s %I %T "%{Referer}i" "%{User-Agent}i"');
$lines = file($accesslogFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$client = new GuzzleHttp\Client(['base_uri' => $base_uri]);
do {
shuffle($lines);
$line = array_pop($lines);
$entry = $parser->parse($line);
$pagePath = explode(" ",$entry->request)[1];
try {
$response = $client->request('GET',$pagePath);
$code = $response->getStatusCode();
$log = print_r($code." ".$pagePath."\n", true);
file_put_contents('/tmp/loadtest-access-log.log', $log, FILE_APPEND);
echo $log;
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
} while (!empty($lines));