1
array_multisort(array_map('filemtime', ($files = glob("*.json"))), SORT_DESC, $files);

This is the most efficient method to sort 45k json files I have found so far. Works great, except in my case the files are constantly being changed by a game server so if a file gets deleted during this sort execution I get a error

String: filemtime(): stat failed for blah.json

Can I handle this with a try and catch exception? I am not having any luck searching for a solution.

halfer
  • 19,824
  • 17
  • 99
  • 186
Chris
  • 11
  • 1

1 Answers1

0

Suppress the error if you don't mind receiving false on failure for certain files:

array_multisort(array_map(function($file) { return @filemtime($file); }, ($files = glob("*.json"))), SORT_DESC, $files);
kmoser
  • 8,780
  • 3
  • 24
  • 40