note 88028 added to function.touch

From: Date: Tue, 06 Jan 2009 19:44:23 +0000
Subject: note 88028 added to function.touch
Groups: php.notes 
Request: Send a blank email to php-notes+get-148901@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: ------ // 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 ---- Server IP: 190.2.55.3 Probable Submitter: 190.137.160.10 ---- Manual Page -- http://www.php.net/manual/en/function.touch.php Edit -- https://master.php.net/note/edit/88028 Del: integrated -- https://master.php.net/note/delete/88028/integrated Del: useless -- https://master.php.net/note/delete/88028/useless Del: bad code -- https://master.php.net/note/delete/88028/bad+code Del: spam -- https://master.php.net/note/delete/88028/spam Del: non-english -- https://master.php.net/note/delete/88028/non-english Del: in docs -- https://master.php.net/note/delete/88028/in+docs Del: other reasons-- https://master.php.net/note/delete/88028 Reject -- https://master.php.net/note/reject/88028 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148901) next »