note 88028 modified in function.touch by danbrown
| From: | danbrown@php.net | Date: | Tue, 06 Jan 2009 19:48:02 +0000 |
| Subject: | note 88028 modified in function.touch by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148903@lists.php.net to get a copy of this message | ||
This example resolve some drawbacks with DayLight Saving Flag and TimeZone in Windows with native
function 'touch()'
See function comments for details
Usage:
------
<?php
// mtime of source File
$time = filemtime("/source.txt");
// Sync mtime at destination file with source file
betouch("/destination.txt",$time);
/**
* Function: Best Effort Touch
* Update recursively mtime at especified file and verify.
*
* This function, resolve 2 drawbacks with native function 'touch()' on Windows:
* - touch() Return incorrect result (PHP v5.2.5)
* - touch() Is affected by DayLight Saving Flag and TimeZone
*
* @access public
* @param String $file Full path to target file
* @param int $time Unix Timestamp
* @param int $offset Offset (Default: 0)
* @return boolean
*/
function betouch($file, $time, $offset = 0){
// Add offset to requested mtime
$new_mtime = $time + $offset;
// Calling native touch
$result = touch($file, $new_mtime, $new_mtime);
// If 'touch()' return OK
if($result){
// Clears file status cache
clearstatcache();
// Get recently stored mtime at destination file
$stored_mtime = filemtime($file);
// Verify if stored is equal to requested mtime
if($stored_mtime == $time){
return true;
}else{
// Calculate offset between stored mtime and requested mtime
$offset = $time - $stored_mtime;
// Recall recursively with new offset and return
return betouch($file, $time, $offset);
}
}
// Native touch() fail
return false;
}
?>
Lucas Fonzalida
Buenos Aires - Argentina
contacto at lucasfonzalida.com.ar
--was--
This example resolve some drawbacks with DayLight Saving Flag and TimeZone in Windows with native
function 'touch()'
See function comments for details
Usage:
------
// mtime of source File
$time = filemtime("/source.txt");
// Sync mtime at destination file with source file
betouch("/destination.txt",$time);
/**
* Function: Best Effort Touch
* Update recursively mtime at especified file and verify.
*
* This function, resolve 2 drawbacks with native function 'touch()' on Windows:
* - touch() Return incorrect result (PHP v5.2.5)
* - touch() Is affected by DayLight Saving Flag and TimeZone
*
* @access public
* @param String $file Full path to target file
* @param int $time Unix Timestamp
* @param int $offset Offset (Default: 0)
* @return boolean
*/
function betouch($file, $time, $offset = 0){
// Add offset to requested mtime
$new_mtime = $time + $offset;
// Calling native touch
$result = touch($file, $new_mtime, $new_mtime);
// If 'touch()' return OK
if($result){
// Clears file status cache
clearstatcache();
// Get recently stored mtime at destination file
$stored_mtime = filemtime($file);
// Verify if stored is equal to requested mtime
if($stored_mtime == $time){
return true;
}else{
// Calculate offset between stored mtime and requested mtime
$offset = $time - $stored_mtime;
// Recall recursively with new offset and return
return betouch($file, $time, $offset);
}
}
// Native touch() fail
return false;
}
Lucas Fonzalida
Buenos Aires - Argentina
contacto at lucasfonzalida.com.ar
http://php.net/manual/en/function.touch.php