heise/shariff
PHP backend for Shariff that fetches social share counts without client-side requests to social networks. Supports Buffer, Facebook, Pinterest, Reddit, Xing, VK and more, with domain whitelisting and configurable caching (filesystem or Laminas adapters).
/api/shariff). Its stateless nature and HTTP-based API align well with Laravel’s RESTful architecture.Illuminate/Cache).Route::get('/shariff', [ShariffController::class, 'getCounts'])).env() or AWS Secrets Manager.domains config) sufficient, or needed additional IP/rate-limiting?Illuminate/Cache (e.g., Redis, file-based).Heise\Shariff\Backend for dependency injection.Http facade./shariff).use Heise\Shariff\Backend;
$shariff = new Backend([
'services' => ['Facebook'],
'Facebook' => ['app_id' => env('FB_APP_ID'), 'secret' => env('FB_SECRET')],
'cache' => ['ttl' => 3600, 'cacheDir' => storage_path('framework/cache/shariff')],
]);
$counts = $shariff->get(request('url'));
return response()->json($counts);
$this->app->singleton(Backend::class, function ($app) {
return new Backend(config('shariff'));
});
config/shariff.php (use Laravel’s config publishing).Heise\Shariff\ServiceInterface.class TwitterService implements ServiceInterface {
public function getShareCount(string $url): int { ... }
}
composer require heise/shariff.config/shariff.php (publish config with php artisan vendor:publish)./api/shariff).heise/shariff for updates (e.g., Facebook API changes).composer update and test thoroughly.Log facade.try {
$counts = $shariff->get($url);
} catch (\Exception $e) {
Log::error("Shariff failed for {$url}: " . $e->getMessage());
}
dd() or Log::debug()./api/shariff endpoint (OpenAPI/Swagger).timeout: 2.0).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Facebook API downtime | Missing share counts for Facebook | Fallback to cached values; alerting. |
| Cache corruption | Stale share counts | Use Redis with persistence; implement cache warming. |
| High traffic spikes | Slow responses, timeouts | Rate limiting (Laravel Middleware); queue requests. |
| PHP memory limits | Worker crashes | Increase memory_limit; optimize Guzzle requests. |
| Third-party API rate limits | Throttled requests | Implement exponential |
How can I help you explore Laravel packages today?