I wouldn't use filemtime(), for one specific reason: it only works for checking local files on the same host where the PHP code is running.
It's common in modern app deployments that you deploy PHP code to a different host than the one that serves static resources. In fact, it's typical to deploy PHP code to multiple app servers behind a load-balancer, so you can do rolling deployments without suffering any downtime.
You might not have this architecture today. You might deploy PHP code to the same host where your static files live, and your database too. But as your app outgrows a single host, or needs to have uninterrupted operation during deployments, you'll eventually need to scale out to multiple hosts. It would be better to plan for that early, and don't implement code that prevents you from scaling out if you can avoid it.
None of the PHP app servers would have direct access to the filesystem where the static files are kept. If they did, you'd have to do one of the following:
- Store duplicate copies of the static files on each PHP app server, using lots more storage space. Then worry about keeping them in sync, have some back-end scripts to continually check that all hosts have the same set of files, etc.
- Make the filesystem for static files remotely mounted to all the PHP app hosts, via NFS or similar protocol. Then the
filemtime()
checks would become somewhat slower, because they're going over NFS. And you'd have to worry about NFS mounts going away, security enforcement, configuring NFS when you add a new app host, and so on.
For these reasons I'd choose to put the timestamp in the database, since you already have file metadata (the pathname) stored there anyway.