PHPackages                             tourze/symfony-temp-file-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. tourze/symfony-temp-file-bundle

ActiveSymfony-bundle[File &amp; Storage](/categories/file-storage)

tourze/symfony-temp-file-bundle
===============================

Symfony临时文件集中管理与自动清理bundle

1.1.0(6mo ago)02.0k3MITPHPCI passing

Since Apr 23Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/tourze/symfony-temp-file-bundle)[ Packagist](https://packagist.org/packages/tourze/symfony-temp-file-bundle)[ RSS](/packages/tourze-symfony-temp-file-bundle/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (12)Versions (6)Used By (3)

symfony-temp-file-bundle
========================

[](#symfony-temp-file-bundle)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Stable Version](https://camo.githubusercontent.com/f972c564a7a772dc82cafa75d172615df93e393cb6cdc0d9210398b225e56eec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f73796d666f6e792d74656d702d66696c652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-temp-file-bundle)[![License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/35a3bdb1bce06d7a3dbf9e85884c3825a7ae0a352825e3e64ecc741b9d690087/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://php.net/)[![Symfony Version](https://camo.githubusercontent.com/bb059eb51b265fee15fb5e0ad36f1d69aa1d588933655beb9dbe685dd84968df/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73796d666f6e792d253345253344362e342d3030303030302e7376673f7374796c653d666c61742d737175617265)](https://symfony.com/)[![Code Coverage](https://camo.githubusercontent.com/994d68acb2aadf1c3c7711ddcb3b30429246a6c05da9e601f62c3f932ac795a8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/tourze/php-monorepo/tree/master/packages/symfony-temp-file-bundle)

Introduction
------------

[](#introduction)

`symfony-temp-file-bundle` is a Symfony bundle for centralized management and automatic cleanup of temporary files. It ensures that temporary files generated during HTTP requests or console commands are automatically deleted at the end of the process, reducing the risk of leftover temp files.

Features
--------

[](#features)

- **Unified temporary file management**: Centralized creation and deletion of temporary files
- **Automatic cleanup**: Files are automatically deleted at the end of HTTP requests and console commands
- **Multiple event listeners**: Supports `KernelEvents::TERMINATE`, `KernelEvents::EXCEPTION`, `ConsoleEvents::TERMINATE`, `ConsoleEvents::ERROR`
- **Simple API**: Easy-to-use methods for generating and managing temporary files
- **Zero configuration**: Works out of the box with minimal setup
- **Memory efficient**: Uses array shifting to manage file cleanup

Installation
------------

[](#installation)

### Requirements

[](#requirements)

- PHP &gt;= 8.1
- Symfony &gt;= 6.4

### Composer

[](#composer)

```
composer require tourze/symfony-temp-file-bundle
```

### Manual Registration (Symfony Flex will register automatically in most cases)

[](#manual-registration-symfony-flex-will-register-automatically-in-most-cases)

Add to `config/bundles.php`:

```
Tourze\TempFileBundle\TempFileBundle::class => ['all' => true],
```

Quick Start
-----------

[](#quick-start)

### Generate a Temporary File

[](#generate-a-temporary-file)

```
use Tourze\TempFileBundle\Service\TemporaryFileService;

// Inject TemporaryFileService
$tempFile = $temporaryFileService->generateTemporaryFileName('prefix_', 'txt');
file_put_contents($tempFile, 'hello world');
// The temp file will be automatically deleted at the end of the request or command
```

### Register an Existing Temp File for Auto-Cleanup

[](#register-an-existing-temp-file-for-auto-cleanup)

```
// Register an existing file for automatic cleanup
$temporaryFileService->addTemporaryFile($filePath);
```

### Generate Temporary File Without Extension

[](#generate-temporary-file-without-extension)

```
// Generate temporary file without extension
$tempFile = $temporaryFileService->generateTemporaryFileName('data_');
// Will create a file like: /tmp/data_abc123
```

API Documentation
-----------------

[](#api-documentation)

### TemporaryFileService

[](#temporaryfileservice)

#### Methods

[](#methods)

- `generateTemporaryFileName(string $prefix, ?string $ext = null): string`

    - Generate a temporary file name with optional extension
    - The file is automatically registered for cleanup
    - Returns the full path to the temporary file
- `addTemporaryFile(string $file): void`

    - Register an existing file for automatic cleanup
    - Useful for files created outside the service
- `reset(): void`

    - Manually clear the temporary file list
    - Usually called automatically by event listeners

#### Event Listeners

[](#event-listeners)

The service automatically cleans up temporary files on these events:

- `KernelEvents::TERMINATE` - Normal HTTP request termination
- `KernelEvents::EXCEPTION` - HTTP request exception
- `ConsoleEvents::TERMINATE` - Console command termination
- `ConsoleEvents::ERROR` - Console command error

#### Configuration

[](#configuration)

No configuration is required. The service is automatically registered and configured when the bundle is installed.

Contributing
------------

[](#contributing)

- Issues and PRs are welcome
- Follow PSR-12 coding style
- Please ensure all PHPUnit tests pass before submitting

License
-------

[](#license)

MIT License © tourze

Changelog
---------

[](#changelog)

See \[CHANGELOG.md\] or Git commit history for details.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance66

Regular maintenance activity

Popularity17

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~60 days

Total

5

Last Release

198d ago

Major Versions

0.0.3 → 1.0.02025-11-01

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13899502?v=4)[tourze](/maintainers/tourze)[@tourze](https://github.com/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-symfony-temp-file-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-symfony-temp-file-bundle/health.svg)](https://phpackages.com/packages/tourze-symfony-temp-file-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[symfony/security-bundle

Provides a tight integration of the Security component into the Symfony full-stack framework

2.5k185.6M2.4k](/packages/symfony-security-bundle)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M577](/packages/shopware-core)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
