note 107565 added to class.mongodate
| From: | richard at securebucket dot com | Date: | Fri, 17 Feb 2012 15:32:30 +0000 |
| Subject: | note 107565 added to class.mongodate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186198@lists.php.net to get a copy of this message | ||
I wanted a way to check the age of a record. This code will calculate the time between the creation
date of the record, and return the seconds. I use it for caching pages similar to the max-age
header in a browser. If the record is older, than my limit it deletes itself.
function microtime_diff( $start, $end=NULL ) {
if( !$end ) {
$end= microtime();
}
list($start_usec, $start_sec) = explode(" ", $start);
list($end_usec, $end_sec) = explode(" ", $end);
$diff_sec= intval($end_sec) - intval($start_sec);
$diff_usec= floatval($end_usec) - floatval($start_usec);
return floatval( $diff_sec ) + $diff_usec;
}
microtime_diff($cache['stamp']->sec);
----
Server IP: 69.147.83.197
Probable Submitter: 98.77.140.159
----
Manual Page -- http://www.php.net/manual/en/class.mongodate.php
Edit -- https://master.php.net/note/edit/107565
Del: integrated -- https://master.php.net/note/delete/107565/integrated
Del: useless -- https://master.php.net/note/delete/107565/useless
Del: bad code -- https://master.php.net/note/delete/107565/bad+code
Del: spam -- https://master.php.net/note/delete/107565/spam
Del: non-english -- https://master.php.net/note/delete/107565/non-english
Del: in docs -- https://master.php.net/note/delete/107565/in+docs
Del: other reasons-- https://master.php.net/note/delete/107565
Reject -- https://master.php.net/note/reject/107565
Search -- https://master.php.net/manage/user-notes.php