Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Shariff Laravel Package

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).

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Microservice/Backend Fit: Shariff is designed as a lightweight, self-contained backend service, making it ideal for integration into a Laravel application as a dedicated microservice or standalone endpoint (e.g., /api/shariff). Its stateless nature and HTTP-based API align well with Laravel’s RESTful architecture.
  • Decoupled Design: The package abstracts social media share-count logic, reducing frontend complexity. This fits Laravel’s modular philosophy, allowing the TPM to treat it as a third-party service rather than a core feature.
  • Caching Layer: Built-in caching (Laminas Cache) supports performance optimization, reducing external API calls. Laravel’s native caching (Redis, Memcached, or file-based) can be leveraged for consistency.

Integration Feasibility

  • Laravel Compatibility:
    • PHP Version: Supports PHP 8.1–8.4 (Laravel 10+ aligns with this).
    • Dependencies: Uses Guzzle (already in Laravel’s ecosystem) and Laminas Cache (replaceable with Laravel’s Illuminate/Cache).
    • HTTP Client: Guzzle is Laravel’s default HTTP client, minimizing friction.
  • Deployment Models:
    • Option 1: Deploy as a separate Laravel route (e.g., Route::get('/shariff', [ShariffController::class, 'getCounts'])).
    • Option 2: Containerize as a microservice (Docker) for scalability.
    • Option 3: Integrate via Laravel Queues for async processing (e.g., cache updates).
  • Frontend Integration: Works with Shariff’s JavaScript frontend (or custom implementations), requiring only a backend endpoint.

Technical Risk

  • Service-Specific Risks:
    • Facebook API: Requires app registration and secret management (risk: API deprecation or rate limits).
    • Third-Party Dependencies: Guzzle/Laminas updates may introduce breaking changes (mitigate via CI testing).
  • Performance:
    • External API calls (e.g., Facebook Graph) may introduce latency. Mitigate with aggressive caching (TTL tuning).
    • High traffic could strain the backend; consider rate limiting or queue-based processing.
  • Maintenance:
    • Package is actively maintained (last release: 2026), but social media APIs (e.g., Facebook) may change independently.
    • Risk of Forking: If upstream changes break compatibility, a custom fork may be needed.

Key Questions

  1. Scalability Needs:
    • Will share-count requests scale to high traffic? If yes, consider horizontal scaling (e.g., Kubernetes) or CDN caching (e.g., Varnish).
  2. Security:
    • How will Facebook app secrets be stored? Use Laravel’s env() or AWS Secrets Manager.
    • Is domain whitelisting (domains config) sufficient, or needed additional IP/rate-limiting?
  3. Monitoring:
    • How will failures (e.g., Facebook API downtime) be monitored? Integrate with Laravel’s Horizon or Sentry.
  4. Customization:
    • Are additional services (e.g., LinkedIn, Twitter) needed? Extend via custom service classes.
  5. Compliance:
    • Does GDPR/privacy law require user consent for tracking? Shariff avoids tracking cookies, but ensure compliance with your legal team.

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Replace Laminas Cache with Laravel’s Illuminate/Cache (e.g., Redis, file-based).
    • Use Laravel’s Service Container to bind Heise\Shariff\Backend for dependency injection.
    • Leverage Laravel’s HTTP Client (Guzzle under the hood) for consistency.
  • Database:
    • No database required; caching is file-based or external (Redis/Memcached).
  • Frontend:
    • Integrate with Shariff’s JavaScript frontend or build a custom API consumer using Laravel’s Http facade.

Migration Path

  1. Phase 1: Proof of Concept (PoC)
    • Deploy Shariff in a Laravel subdirectory (e.g., /shariff).
    • Test with a single service (e.g., Facebook) and validate JSON responses.
    • Example:
      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);
      
  2. Phase 2: Laravel Integration
    • Create a Service Provider to configure Shariff globally:
      $this->app->singleton(Backend::class, function ($app) {
          return new Backend(config('shariff'));
      });
      
    • Publish config via config/shariff.php (use Laravel’s config publishing).
  3. Phase 3: Production Deployment
    • Containerize Shariff (Docker) or deploy as a Laravel route.
    • Set up cron jobs for cache invalidation (if TTL-based).
    • Monitor with Laravel’s Logging or Prometheus.

Compatibility

  • Laravel Versions: Tested with PHP 8.1–8.4; Laravel 10+ is compatible.
  • Caching Backends:
    • Default: Filesystem (works out-of-the-box).
    • Recommended: Redis/Memcached (configure via Laravel’s cache config).
  • Service Extensibility:
    • Add custom services by implementing Heise\Shariff\ServiceInterface.
    • Example:
      class TwitterService implements ServiceInterface {
          public function getShareCount(string $url): int { ... }
      }
      

Sequencing

  1. Pre-requisites:
    • Register Facebook app (if using Facebook service).
    • Set up Laravel caching (Redis recommended).
  2. Development:
    • Install via Composer: composer require heise/shariff.
    • Configure config/shariff.php (publish config with php artisan vendor:publish).
  3. Testing:
    • Unit test service responses (mock Guzzle).
    • Load test with high request volumes.
  4. Deployment:
    • Deploy backend endpoint (e.g., /api/shariff).
    • Update frontend to call the new endpoint.

Operational Impact

Maintenance

  • Dependency Updates:
    • Monitor heise/shariff for updates (e.g., Facebook API changes).
    • Use Laravel’s composer update and test thoroughly.
  • Cache Management:
    • Laravel’s cache system can manage Shariff’s cache (e.g., Redis TTL).
    • Implement a cache warming cron job for critical pages.
  • Logging:
    • Log failures (e.g., Facebook API errors) via Laravel’s Log facade.
    • Example:
      try {
          $counts = $shariff->get($url);
      } catch (\Exception $e) {
          Log::error("Shariff failed for {$url}: " . $e->getMessage());
      }
      

Support

  • Troubleshooting:
    • Common issues: Facebook API rate limits, malformed URLs, cache corruption.
    • Debug with Laravel’s dd() or Log::debug().
  • Service-Level Agreements (SLAs):
    • Define uptime SLAs for the Shariff backend (e.g., 99.9% availability).
    • Use Laravel’s Queue workers to retry failed requests.
  • Documentation:
    • Document the /api/shariff endpoint (OpenAPI/Swagger).
    • Create a runbook for cache invalidation and API failures.

Scaling

  • Horizontal Scaling:
    • Deploy multiple Shariff instances behind a load balancer (e.g., Nginx).
    • Use Redis for shared caching to avoid cache stampedes.
  • Vertical Scaling:
    • Increase PHP worker processes (e.g., Plesk/PHP-FPM tuning).
    • Optimize Guzzle timeouts (e.g., timeout: 2.0).
  • Database:
    • No database scaling needed; caching is external.

Failure Modes

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
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
adachsoft/php-code-style