php - 随机选择一个文件夹/文件,然后更新时间戳

I have a php script that pretty much randomly select a file within a few sub folders for me. I need help touching/updating the timestamp of the folders/file that it picked, and than at the next time I run this script, I want it to randomly select from the 100 folders/file that has the oldest timestamp. I have about 500k of these folders and directories, please guide me and let me know if what I am currently doing is efficient:

    $tf= glob('/var/lib/asterisk/agi-bin/tf/*/*');

if (empty($tf) === false)
{
    $randomtf = $tf[array_rand($tf)];
    include($randomtf);
}
echo substr($randomtf,-11);

any kind of help I can get on this is greatly appreciated!

See: php find oldest file in a folder to pick up the oldest file.

Touch the file choosen using touch()

I would highly not recommend to do this stuff regularly over 500k files for performance reasons.