【问题标题】:How to catch error during mass sort of files that constantly change如何在不断变化的大量文件中捕获错误
【发布时间】:2020-08-15 14:14:09
【问题描述】:
array_multisort(array_map('filemtime', ($files = glob("*.json"))), SORT_DESC, $files);

这是迄今为止我发现的对 45k json 文件进行排序的最有效方法。效果很好,除了在我的情况下,游戏服务器会不断更改文件,所以如果在这种排序执行期间文件被删除,我会收到错误

字符串:filemtime():blah.json 的统计失败

我可以通过 try and catch 异常来处理这个问题吗?我没有任何运气寻找解决方案。

【问题讨论】:

    标签: php sorting array-map filemtime array-multisort


    【解决方案1】:

    如果您不介意在某些文件失败时收到false,请抑制错误:

    array_multisort(array_map(function($file) { return @filemtime($file); }, ($files = glob("*.json"))), SORT_DESC, $files);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-23
      • 1970-01-01
      • 2015-03-07
      • 2021-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多