aliyuncs/oss-sdk-php
Alibaba Cloud OSS SDK for PHP (V1): connect to Object Storage Service to upload, download, and manage files. Composer install, works on PHP 5.3+ with cURL. Supports common OSS operations for websites and applications with secure, reliable storage.
Pros:
OssClient and inject it into controllers/services.OssClient, OssException) aligns with Laravel’s dependency injection and service-oriented patterns. Key features like bucket/object operations are encapsulated in reusable methods.oss.object.uploaded) for logging, notifications, or caching.Storage facade) by wrapping OSS operations behind a custom OssAdapter (e.g., extending FilesystemAdapter).Cons:
OssClient instance maintains state (e.g., credentials, endpoint), which may require singleton patterns or context binding in Laravel’s service container to avoid reinstantiation overhead.OSS_CHECK_MD5 in v2.2.3).local/s3 filesystem with OSS via a custom OssAdapter (e.g., extending Illuminate\Filesystem\FilesystemAdapter).mix/vite) for optimized delivery.Storage events (e.g., filesystem.created) to sync OSS operations with local caches or databases..env can store OSS_ACCESS_KEY_ID/SECRET, but credentials rotation requires integration with Laravel’s config or cache systems.OssException to map to Laravel’s HttpException or log via Log::error() for consistency.UploadFileStream to avoid timeouts.config/oss.php risks exposure. Mitigate with:
config['oss']['timeout'] tuning.composer require aliyuncs/oss-sdk-php:^2.7 to enforce LTS versions.Storage facade lacks native OSS ACL support. Implement a BucketPolicy service to manage permissions.StorageInterface) for future AWS/S3 compatibility?putObjectAcl updates?PutObject latency) be exposed via Laravel’s Prometheus client or a custom dashboard?backup package integrate with OSS’s copyObject API?local/s3 drivers with a custom oss driver (extend Illuminate\Filesystem\FilesystemAdapter).
// config/filesystems.php
'oss' => [
'driver' => 'oss',
'key' => env('OSS_ACCESS_KEY_ID'),
'secret' => env('OSS_ACCESS_KEY_SECRET'),
'endpoint' => env('OSS_ENDPOINT'),
'bucket' => env('OSS_BUCKET'),
'region' => env('OSS_REGION', 'oss-cn-hangzhou'),
'use_path_style' => env('OSS_USE_PATH_STYLE', false),
],
UploadToOssJob).OssObjectUploaded) to trigger notifications or cache invalidation.Storage facade mocking to test OSS interactions in unit tests.curl and openssl PHP extensions are enabled (required by OSS SDK).guzzlehttp/guzzle) is low; OSS SDK uses its own HTTP layer.local filesystem with OSS for non-critical assets (e.g., logs, backups).OssService facade to wrap OssClient:
// app/Services/OssService.php
class OssService {
public function __construct(OssClient $client) {}
public function upload(string $path, string $object): void {}
public function generatePresignedUrl(string $object, int $expires): string {}
}
Storage facade:
Storage::disk('oss')->put('file.txt', 'content');
HasFile trait for model uploads:
use Illuminate\Support\Facades\Storage;
class Post extends Model {
public function uploadCover($file) {
$path = $file->store('covers', 'oss');
return $this->update(['cover_path' => $path]);
}
}
ValidateOssSignature) for API endpoints.tus protocol).Storage facade. Direct OssClient usage requires refactoring.spatie/laravel-medialibrary (may need OSS adapter).endpoint in .env matches the OSS region (e.g., `oss-cHow can I help you explore Laravel packages today?