I need to show in a PHP
web page all the images in a folder. A pagination is required. The images can be more than 10,000, so a good performance is important, and here is where my doubt comes from, what is more efficient?
Paginate the images of the folder using scandir
.
Automatically save the name of all images in a database and load them with a Mysqli
query (probably also convenient to use a temporary cache).
Any other suggestions you can give me.
The website uses WordPress
as the engine, but the images are uploaded to a subdomain using a PHP file isolated from Wordpress ...
I thought about saving the name of all the images like a WordPress Custom-Post-Type
(using mysqli
basic queries) and paginate them like any other publication, but I think that, due to the amount, it would harm the overall performance of the website (because the custom-post-type
are saved in the same table as the other publications)...
The website receives more than 30 thousand daily visits that it must support.
PD: Sorry for the bad explanation but it is complicated to explain, and more in another language.
Use a custom table or a second database.
You are right to consider avoiding repeatedly calling scandir for every paginated request. You can access the global $wpdb
object and do custom queries to manage the contents of your directory.
I'd lean towards just managing the image data separately from WordPress. Since you are already using a non WP upload script just create a new DB and use it to keep track of the directory contents in that script. Then paginated results is a very simple DB query. This keeps the WP database smaller and faster and is not overkill for the magnitude of images and visits you must handle.