1. Go to this page and download the library: Download litesoc/litesoc-php 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/ */
litesoc / litesoc-php example snippets
use LiteSOC\LiteSOC;
// Initialize the SDK
$litesoc = new LiteSOC('your-api-key');
// Track a login failure - LiteSOC auto-enriches with GeoIP & Network Intelligence
$litesoc->track('auth.login_failed', [
'actor_id' => 'user_123',
'actor_email' => '[email protected]',
'user_ip' => '192.168.1.1', // Required for Security Intelligence
'metadata' => ['reason' => 'invalid_password']
]);
// Flush remaining events before shutdown
$litesoc->flush();
use LiteSOC\SecurityEvents;
// Use predefined security event types
$litesoc->track(SecurityEvents::AUTH_LOGIN_FAILED, [
'actor_id' => 'user_123',
'user_ip' => '192.168.1.1'
]);
// Get all 26 standard events
$allEvents = SecurityEvents::all();
// Validate an event type
if (SecurityEvents::isValid('auth.login_failed')) {
// Valid standard event
}
use LiteSOC\LiteSOC;
$litesoc = new LiteSOC('your-api-key');
// Make an API call first
$alerts = $litesoc->getAlerts();
// Get plan metadata from response headers
$planInfo = $litesoc->getPlanInfo();
if ($planInfo) {
echo "Plan: " . $planInfo->plan; // e.g., "business", "enterprise"
echo "Retention: " . $planInfo->retentionDays . " days";
echo "Cutoff: " . $planInfo->cutoffDate; // ISO 8601 timestamp
}
// Check if plan info is available
if ($litesoc->hasPlanInfo()) {
// Plan data has been populated
}
$litesoc = new LiteSOC('your-api-key', ['debug' => true]);
// Logs will be printed to stdout
// In a controller or middleware
public function login(Request $request)
{
// ... authentication logic ...
// Queue the security event (fast, no HTTP call yet)
$litesoc->track('auth.login_success', [
'actor_id' => auth()->id(),
'user_ip' => $request->ip()
]);
// Return response to client immediately
$response = redirect('/dashboard');
// Finish the request - client receives response NOW
if (function_exists('fastcgi_finish_request')) {
// Send response headers and body to client
$response->send();
// Close the connection - client is done waiting
fastcgi_finish_request();
// This runs AFTER the client has received their response
$litesoc->flush();
}
return $response;
}
// app/Http/Middleware/FlushLiteSOCEvents.php
namespace App\Http\Middleware;
use Closure;
use LiteSOC\LiteSOC;
class FlushLiteSOCEvents
{
public function __construct(private LiteSOC $litesoc) {}
public function handle($request, Closure $next)
{
return $next($request);
}
/**
* Flush events after response is sent to client
*/
public function terminate($request, $response)
{
// In PHP-FPM, this runs after fastcgi_finish_request()
// The client has already received their response
$this->litesoc->flush();
}
}
// Register in app/Http/Kernel.php
protected $middleware = [
// ... other middleware
\App\Http\Middleware\FlushLiteSOCEvents::class,
];
// app/Jobs/TrackSecurityEvent.php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use LiteSOC\LiteSOC;
class TrackSecurityEvent implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable;
public function __construct(
public string $eventType,
public array $options
) {}
public function handle(LiteSOC $litesoc): void
{
$litesoc->track($this->eventType, $this->options);
$litesoc->flush();
}
}
// Usage - non-blocking, runs in background queue worker
TrackSecurityEvent::dispatch('auth.login_failed', [
'actor_id' => 'user_123',
'user_ip' => request()->ip()
]);