A clean method to use temporary file:
$tmp=array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()]=tmpfile())));
file_put_contents($tmp, 'hello');
echo file_get_contents($tmp);
?>
without need to fclose the tmp file, it will be deleted while the php ends.