Temp file manager.
You can install the latest version via Composer:
composer require denisyukphp/tmpfile-manager
This package requires PHP 8.0 or later.
Build a temp file manager and create a temp file:
<?php
use TmpFileManager\TmpFileManagerBuilder;
use TmpFile\TmpFileInterface;
$tmpFileManager = (new TmpFileManagerBuilder())
    ->withTmpFileDir(sys_get_temp_dir())
    ->withTmpFilePrefix('php')
    ->build()
;
/** @var TmpFileInterface $tmpFile */
$tmpFile = $tmpFileManager->create();All temp files created the manager will be purged automatically by default.
- Default configuration
 - Creating temp files
 - Loading temp files
 - Removing temp files
 - Auto-purging
 - Check unclosed resources
 - Garbage collection
 - Lifecycle events
 
Read more about temp file on Habr.