Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8160975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:23:54+00:00 2026-06-06T18:23:54+00:00

I know my file system is storing the file modification time in milliseconds but

  • 0

I know my file system is storing the file modification time in milliseconds but I don’t know of a way to access that information via PHP. When I do an ls --full-time I see this:

-rw-r--r-- 1 nobody nobody 900 2012-06-29 14:08:37.047666435 -0700 file1
-rw-r--r-- 1 nobody nobody 900 2012-06-29 14:08:37.163667038 -0700 file2

I’m assuming that the numbers after the dot are the milliseconds.

So I realize I could just use ls and have it sort by modification time, like this:

$filelist = `ls -t`;

However, the directory sometimes has a massive number of files and I’ve noticed that ls can be pretty slow in those circumstances.

So instead, I’ve been using find but it doesn’t have a switch for sorting results by modification time. Here’s an example of what I’m doing now:

$filelist = `find $dir -type f -printf "%T@ %p\n" | sort -n | awk '{print $2}'`;

And, of course, this doesn’t sort down to the milliseconds so files that were created in the same second are sometimes listed in the wrong order.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:23:55+00:00Added an answer on June 6, 2026 at 6:23 pm

    Only a few filesystems (like EXT4) actually store these times up to nanosecond precision. It’s not something that’s guaranteed to be available, on other filesystems (like EXT3) you’ll notice that the fractional part is .000000000

    Now, if this feature is really important for you, you could write a specialized PHP extension. This will bypass the calls to external utilities and should be a great deal faster. The process of creating extension is well explained in many places, like here. A reasonable approach to such an extension could be an alternative fstat function implementation that exposes the high-precision fields available in the stat structure defined in /usr/include/bits/stat.h nowadays.

    As usual, nothing is free. This extension will have to be maintained, it’s probably not possible to get it running on hosted environments, etc. Plus, your php solution will only run on servers where your extension was deployed (although that can circumvented by falling back on the ls based technique if the extension is not detected).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that a good unit test should never access the file system. So
Sometimes I know a file is not so deep away, but a very dense
Anyone know what function or file in linux holds the algorithm that finds a
I know how to use file.lastModified(); . When I println that I get (for
I am coding a forum system using PHP. I am currently storing a threads
What is the best way to open a Word file that was stored as
I know that ProfileCommon is not available in a Web Application Project (WAP), but
does anybody know how to make EJBTimers persistent not in filesystem, but in selected
I know it is a condition of hard links that they cannot span filesystems.
I would like to know if a file is open by any process (including

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.