# Warning: stream_wrapper_register(): Protocol 's3' is already defined in /var/www/app/src/Storage/S3Wrapper.php on line 25

- **ID:** `php/stream-wrapper-already-registered`
- **Domain:** php
- **Category:** runtime_error
- **Error Code:** `E_WARNING`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

A custom stream wrapper for the 's3' protocol is registered twice, often due to duplicate autoloading or multiple includes of the same registration code.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 8.0 | active | — | — |
| 8.1 | active | — | — |
| 8.2 | active | — | — |
| 8.3 | active | — | — |

## Workarounds

1. **Add a guard clause before registration: if (!in_array('s3', stream_get_wrappers())) { stream_wrapper_register('s3', 'S3StreamWrapper'); }** (95% success)
   ```
   Add a guard clause before registration: if (!in_array('s3', stream_get_wrappers())) { stream_wrapper_register('s3', 'S3StreamWrapper'); }
   ```
2. **Ensure the registration code runs only once by moving it to a service provider or bootstrap file with a singleton pattern.** (90% success)
   ```
   Ensure the registration code runs only once by moving it to a service provider or bootstrap file with a singleton pattern.
   ```

## Dead Ends

- **** — This only masks the underlying duplicate registration issue and may break other code expecting the 's3' protocol. (95% fail)
- **** — Removing the guard will cause a fatal error when the wrapper is registered twice instead of a warning. (80% fail)
