简体   繁体   English

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

[英]php - randomly select a folder/file then update timestamp

I have a php script that pretty much randomly select a file within a few sub folders for me. 我有一个PHP脚本,几乎可以为我随机选择几个子文件夹中的文件。 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. 我需要帮助来触摸/更新它选择的文件夹/文件的时间戳,比之下次运行该脚本时,我希望它从具有最早时间戳的100个文件夹/文件中随机选择。 I have about 500k of these folders and directories, please guide me and let me know if what I am currently doing is efficient: 我大约有500k的这些文件夹和目录,请指导我,让我知道我目前正在执行的操作是否有效:

    $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. 请参阅: php在文件夹中查找最旧的文件以提取最旧的文件。

Touch the file choosen using touch() 触摸使用touch()选择的文件

I would highly not recommend to do this stuff regularly over 500k files for performance reasons. 我会强烈建议不要做这个东西经常超过500k的文件性能方面的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM