获取具有修改日期和大小的大型文件列表的高效方法

I am using PHP 5.6 on Linux. I am getting a list of files and directories in a directory

$directory_listing = scandir($path);

I know I could do something similar to following to get an array of the filenames plus modified date and size.

$listings_final = array();
foreach ($directory_listing as $listing) {
    $listings_final[]['listing_name'] = $listing;
    $listings_final[]['listing_modified'] = filemtime($listing);
    $listings_final[]['listing_size'] = filesize($listing);
}

This will be slow when the number of files is extremely large. Is there a more performant way to archive this?

Not likely. In accessing the filesystem, the metadata for each file is grabbed per file, not in bulk. Even relatively low-level tools like ls do it this way. So if you have 10,000 files in a directory, there's not going to be any way around making 10,000 separate calls to grab the metadata for all of the files. There may be some tool that purports to get it all in one go, but it's just going to be abstracting the fact that it's looping through all files in a directory to get the information, and isn't going to be any faster.

The only way I know of to do this would be to create something that accesses the filesystem directly for this information. However, that would not be recommended, as it makes your application then dependent on specific filesystems (i.e. ext4).

Your best bet is going to be to grab the initial file listing for the directory and populate that, since that can be done quickly. Then, asynchronously, grab the metadata for each file and populate your application. This way, the user can begin interact with your application without having to wait for all of the metadata to load.