fileatime

  • To get the last access time of a file in PHP, we use fileatime. It returns an integer with a timestamp (seconds since Unix epoch).

    PHP

    $timestamp = fileatime('/path/to/foobar');
    print $timestamp;
     
    //=> 1205621108

    Ruby’s File.atime method accomplishes the same task, only it returns an instance of Time instead of an integer:

    Ruby

    time = File.atime('/path/to/foobar')
    p time
     
    #=> Sat Mar 15 15:45:08 -0700 2008

    If you then need the timestamp (seconds since Unix epoch) as an integer, use the Time#to_i method:

    Ruby

    timestamp = time.to_i
    p timestamp
     
    #=> 1205621108

    see also

Looking for Rails or PHP web application development, integration, and training?

Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.