Good day all.
I'm developing a script that will randomly choose an image and post it on a platform. I'm actually investigating on "how to chose the random image", I'd like, if someone as some information, to understand which is the most efficient way to do this in terms of speed and resources. Images will be divided into categories (or directories).
Actually my solutions are the following:
1) randomly select a directory on the server (which will be the category) and then randomly select a file into that directory. This solution is good because I don't have to pre-process images, but I can simply upload them into the proper directory on the server.
2) Upload the images and put the filename and category on a database, then randomly select both of them with:
$query = 'SELECT * FROM table ORDER BY RAND() LIMIT 1';
3) Images are processed once a day by a chron script that will write directories and filenames into a txt file, this file is then included into the php script (json? an array?) which randomly select the image to use.
4) images are processed once a day by a chron and a txt file with all images is created, the php script will then select a random line from the file. (the difference between the point 3 is that in point 3 the list is included in the php script so the data will be structured as a json, or an array).
considering something like 20 categories and 1000 images per category, which will be the better way to do this? is there some other way I did not think? My concern is to have a script with a lowest cpu/ram impact as possible.
thanks in advance.
Aucun commentaire:
Enregistrer un commentaire