php - Decrease time searching images in folder -


i've built site in php, user can choose image folder want see. there's more 1 folder , each folder have more 10,000 images.

however, want find newest image in each folder, taking long time. how can speed up?

edit

$file = new globiterator($d.'*.jpg', filesystemiterator::key_as_filename); foreach ($file $f) {     $files[] = $d.$f->getfilename(); } sort($files, sort_natural | sort_flag_case); $path = end($files); return $path; 

instead of scanning each directory in real-time (i'm guessing you're doing - it's hard tell due paucity of information in question), avoid speed issue if store meta information on each image in database (including path file on disk - don't store actual image in database).

by doing this, you'll able carry out high-speed searches based on criteria such last added, etc. long have necessary fields/the appropriate indexes set.

n.b.: it's important ensure database , filesystem keep in sync, ensure delete operations carried out via code (which remove both database record , file on disk).


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -