I'm trying to determine if it's better to store an image's last modified date in a MySQL database or use the PHP function filemtime.
In my case, all of the website info is stored in a database (cms), so there is always a query to pull the image path, etc. The question is for caching purposes I need to have my HTML output something like this <img src="/img/photo.jpg?v20190613" />
. From what I read on the php.net website this function is cached. So would it use fewer resources to add a field to the database table that stores the last updated timestamp or use this function each time? Are there any advantages either way? I'm looking for whatever is going to give the best performance.
Using MySQL database is mostly better
MySQL does and can do BST indexing and Query Caching, which is a luxury not always available to a filesystem.
And looking into your particular case, saving timestamp in the database would be much faster, because timestamp would be stored with the image path, so you probably get both timestamp and filepath in a single go, on the other hand using filemtime would be costly because php would request filesystem, and filesystem would search the file to give you it's timestamp.