Alternative to tmpfile() function.
You can install the latest version via Composer:
composer require denisyukphp/tmpfile
This package requires PHP 8.0 or later.
A temp file will be removed after PHP finished:
<?php
use TmpFile\TmpFile;
$tmpFile = new TmpFile();
file_put_contents($tmpFile, 'Meow!');
rename($tmpFile, '/path/to/meow.txt');
Read more about temp file on Habr.