Weave Code
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

Tus Php Laravel Package

ankitpokhrel/tus-php

PHP server/client implementation of the tus resumable upload protocol. Supports large, chunked uploads with pause/resume, retries, and offsets; integrates with popular PHP frameworks and storage backends, offering configurable middleware, events, and validation.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Aligns perfectly with Laravel’s modular, event-driven architecture (e.g., integrates with Laravel’s middleware, events, and storage systems).
    • Supports chunked/resumable uploads, addressing a critical gap for large-file handling (e.g., video, medical imaging, or user-generated content).
    • TUS protocol compliance ensures interoperability with existing clients (e.g., tus-js, tus-ios) and future-proofing.
    • Backend-agnostic storage (supports S3, local FS, custom adapters) fits Laravel’s storage abstraction layer (\Illuminate\Contracts\Filesystem\Filesystem).
    • Event hooks (e.g., UploadStarted, UploadCompleted) enable seamless integration with Laravel’s job queues (e.g., process files post-upload via queues).
  • Cons:

    • No built-in Laravel service provider: Requires manual bootstrapping (though minimal).
    • Limited Laravel-specific documentation: May need custom validation/error handling for Laravel’s request lifecycle.
    • Concurrency risks: TUS uploads are stateful; Laravel’s stateless middleware may require session/cookie management for upload tracking.

Integration Feasibility

  • High for Laravel apps needing resumable uploads.
    • Core dependencies: PHP 8.0+, Laravel 8+ (or Symfony 5+).
    • Storage backends: Works with Laravel’s filesystem config (e.g., local, s3, ftp).
    • HTTP routing: Can be mounted as a Laravel route group (e.g., /upload) or middleware.
  • Potential blockers:
    • CORS/CSRF: Must configure CORS headers and CSRF protection for tus endpoints (e.g., via Laravel middleware).
    • Authentication: TUS lacks built-in auth; must integrate with Laravel’s auth (e.g., middleware to validate tokens before uploads).
    • Rate limiting: May need Laravel’s throttle middleware to prevent abuse.

Technical Risk

Risk Area Severity Mitigation Strategy
Protocol compliance Low Test with tus clients (e.g., tus-js) early.
Storage corruption Medium Use Laravel’s filesystem drivers with checksum validation.
Concurrency issues Medium Implement upload locking (e.g., database locked_at field).
Laravel version skew Low Pin package version in composer.json.
Performance bottlenecks Medium Benchmark with large files; optimize chunk size.

Key Questions

  1. Storage Backend:

    • Will the app use Laravel’s default storage or a custom adapter (e.g., database binary)?
    • How will temporary uploads (e.g., .tmp files) be managed during resumption?
  2. Authentication:

    • How will uploads be authenticated? (e.g., API tokens, session cookies, or custom headers?)
    • Will Laravel’s auth:api middleware suffice, or is a custom tus auth layer needed?
  3. Event Handling:

    • Are there post-upload actions (e.g., thumbnail generation, virus scanning) that should trigger via Laravel events/jobs?
    • How will failed uploads be retried or notified to users?
  4. Scaling:

    • Will uploads be handled by a single server, or is a distributed setup (e.g., multiple tus endpoints behind a load balancer) needed?
    • How will upload metadata (e.g., user ID, file type) be persisted and queried?
  5. Monitoring:

    • Are there metrics (e.g., upload success/failure rates, chunk retry counts) that need to be logged for observability?

Integration Approach

Stack Fit

  • Laravel-Specific Advantages:
    • Storage: Leverage Laravel’s Filesystem contracts (e.g., Storage::disk('s3')->put()) for seamless backend switching.
    • Events: Bind tus events to Laravel’s event system (e.g., UploadCompleted → dispatch FileUploaded event).
    • Validation: Use Laravel’s FormRequest or Validate to sanitize upload metadata.
    • Queues: Process post-upload tasks (e.g., video encoding) via Laravel Queues.
  • Compatibility:
    • TUS Clients: Works with any tus-compliant client (e.g., tus-js, tus-ios, tus-android).
    • Existing APIs: Can coexist with REST/GraphQL endpoints (e.g., /api/upload for tus, /api/files for metadata).

Migration Path

  1. Phase 1: Proof of Concept (1–2 weeks)

    • Install package: composer require ankitpokhrel/tus-php.
    • Configure a basic tus endpoint (e.g., routes/web.php):
      use AnkitPokhrel\Tus\TusController;
      Route::tus('upload', TusController::class);
      
    • Test with a tus client (e.g., tus-js) and Laravel’s storage.
    • Validate resumption after network interruptions.
  2. Phase 2: Laravel Integration (1–2 weeks)

    • Authentication: Add middleware to validate uploads (e.g., check Authorization header).
      Route::tus('upload', TusController::class)->middleware('auth:api');
      
    • Storage: Configure custom adapter for Laravel’s filesystem (if needed).
    • Events: Bind tus events to Laravel’s listeners (e.g., trigger a job on UploadCompleted).
      event(new FileUploaded($filePath, $metadata));
      
    • Validation: Add metadata validation via Laravel’s FormRequest.
  3. Phase 3: Production Readiness (1–2 weeks)

    • Monitoring: Log tus events to Laravel’s logging system (e.g., UploadFailed).
    • Rate Limiting: Apply Laravel’s throttle middleware to tus routes.
    • Cleanup: Implement a cron job to purge old temporary uploads.
    • Testing: Load test with large files (e.g., 1GB+) and simulate failures.

Compatibility

  • Laravel Versions: Tested with Laravel 8+ (PHP 8.0+). For older versions, check composer constraints.
  • Storage Drivers: Works with local, s3, ftp, and custom drivers (implement Filesystem interface).
  • HTTP Servers: Compatible with Laravel’s default server (e.g., php artisan serve) and production servers (e.g., Nginx, Apache).
  • Database: No direct DB dependency, but metadata can be stored in Laravel’s database (e.g., uploads table).

Sequencing

  1. Prerequisites:
    • Laravel app with PHP 8.0+ and Composer.
    • Storage backend configured (e.g., S3 bucket or local disk).
  2. Core Integration:
    • Install package and configure tus routes.
    • Implement authentication/middleware.
  3. Enhancements:
    • Add event listeners for post-upload processing.
    • Configure monitoring/logging.
  4. Optimizations:
    • Tune chunk size and concurrency limits.
    • Implement cleanup for failed uploads.

Operational Impact

Maintenance

  • Pros:
    • MIT License: No vendor lock-in; community-supported.
    • Active Development: Recent releases (2024) indicate ongoing maintenance.
    • Laravel Alignment: Uses familiar patterns (events, storage, middleware).
  • Cons:
    • Documentation Gaps: Laravel-specific use cases may require reverse-engineering.
    • Dependency Updates: Monitor for breaking changes in underlying tus-php or Laravel.
  • Maintenance Tasks:
    • Update package version in composer.json (semver-compliant).
    • Monitor tus protocol updates (e.g., tus protocol spec).
    • Rotate storage credentials (e.g., S3 keys) via Laravel’s .env.

Support

  • Troubleshooting:
    • Common Issues:
      • Uploads stuck in "paused" state → Check storage permissions or tus server logs.
      • Authentication failures → Verify middleware and headers.
      • Chunk corruption → Validate storage checksums or switch backends.
    • Debugging Tools:
      • Laravel’s dd() or Log::debug() for tus events.
      • tus-php’s built-in logging (configure via config/tus.php).
  • Community Resources:
    • GitHub issues (1467 stars → active community).
    • TUS protocol documentation for client-side debugging.

Scaling

  • Horizontal Scaling:
    • Stateless Design: TUS uploads are stateful (tracked via Upload-ID header), so multiple tus servers can share storage (e.g., S3).
    • Load Balancing: Distribute tus endpoints behind a load balancer (e.g., Nginx) with sticky sessions for upload tracking.
    • Concurrency Limits: Configure `max_concurrent
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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle