1. Go to this page and download the library: Download seatlon/cs2-log 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/ */
seatlon / cs2-log example snippets
use CSLog\CS2\Patterns;
$lines = file('server.log', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
$event = Patterns::match($line);
if ($event) {
// Process event
}
}
use CSLog\CS2\Parser;
use CSLog\CS2\Models\RoundStats;
use CSLog\CS2\Models\TeamPlaying;
use CSLog\CS2\Models\ServerCVar;
use CSLog\CS2\Models\Kill;
$logContent = file_get_contents('server.log');
$parser = new Parser();
$events = $parser->parse($logContent);
foreach ($events as $event) {
if ($event instanceof RoundStats) {
echo "Round {$event->roundNumber} at {$event->timestamp->format('H:i:s')}\n";
echo "Score: CT {$event->scoreCT} - {$event->scoreT} T\n";
foreach ($event->players as $playerKey => $stats) {
if ($stats['accountid'] > 0) {
echo " {$stats['accountid']}: {$stats['kills']}K / {$stats['deaths']}D\n";
}
}
} elseif ($event instanceof TeamPlaying) {
echo "Team {$event->side}: {$event->teamName}\n";
echo "Assigned at: {$event->timestamp->format('H:i:s')}\n";
} elseif ($event instanceof ServerCVar) {
echo "Server setting: {$event->cvar} = {$event->value}\n";
} elseif ($event instanceof Kill) {
echo "{$event->attacker->name} killed {$event->victim->name}\n";
echo "Time: {$event->timestamp->diffForHumans()}\n";
}
}
use Carbon\Carbon;
// Filter events by time
$recentEvents = array_filter($events, function($event) {
return $event->timestamp->isAfter(Carbon::now()->subHour());
});
// Get events from specific date
$dateEvents = array_filter($events, function($event) {
return $event->timestamp->isSameDay('2026-01-19');
});
// Group events by hour
$hourlyGroups = collect($events)->groupBy(function($event) {
return $event->timestamp->format('Y-m-d H:00');
});
// Calculate time differences
$firstEvent = $events[0];
$lastEvent = end($events);
$duration = $firstEvent->timestamp->diffInMinutes($lastEvent->timestamp);
echo "Match duration: {$duration} minutes\n";
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.