[Phpfreechat-svn] SF.net SVN: phpfreechat: [1013] trunk/src
Status: Beta
Brought to you by:
kerphi
|
From: <ke...@us...> - 2007-04-01 13:06:42
|
Revision: 1013
http://svn.sourceforge.net/phpfreechat/?rev=1013&view=rev
Author: kerphi
Date: 2007-04-01 06:06:42 -0700 (Sun, 01 Apr 2007)
Log Message:
-----------
[en] Bug fix: use flock() to lock the read and write access in the file container [1h10]
[fr] Bug fix : utilise la fonction flock() pour les acc?\195?\168s en lecture et ?\195?\169criture du conteneur "file" [1h10]
Modified Paths:
--------------
trunk/src/containers/file.class.php
trunk/src/pfctools.php
Modified: trunk/src/containers/file.class.php
===================================================================
--- trunk/src/containers/file.class.php 2007-04-01 11:01:46 UTC (rev 1012)
+++ trunk/src/containers/file.class.php 2007-04-01 13:06:42 UTC (rev 1013)
@@ -91,7 +91,7 @@
}
else
{
- file_put_contents($leaffilename, $leafvalue);
+ flock_put_contents($leaffilename, $leafvalue);
}
// store the value in the memory cache
@@ -157,7 +157,7 @@
if (!file_exists($leaffilename)) return $ret;
if ($withleafvalue)
- $ret["value"][] = file_get_contents($leaffilename);
+ $ret["value"][] = flock_get_contents($leaffilename);
else
$ret["value"][] = NULL;
$ret["timestamp"][] = filemtime($leaffilename);
Modified: trunk/src/pfctools.php
===================================================================
--- trunk/src/pfctools.php 2007-04-01 11:01:46 UTC (rev 1012)
+++ trunk/src/pfctools.php 2007-04-01 13:06:42 UTC (rev 1013)
@@ -403,4 +403,40 @@
}
}
+/**
+ * Almost the Same as file_get_contents except that it uses flock() to lock the file
+ */
+function flock_get_contents($filename, $mode = "rb")
+{
+ $data = '';
+ if (!file_exists($filename)) return $data;
+
+ $size = filesize($filename);
+ if ($size == 0) return $data;
+
+ $fp = fopen( $filename, $mode );
+ if( $fp && flock( $fp, LOCK_SH ) )
+ {
+ $data = fread( $fp, $size );
+ flock($fp, LOCK_UN);
+ }
+ fclose( $fp );
+ return $data;
+}
+
+/**
+ * Almost the Same as file_put_contents except that it uses flock() to lock the file
+ */
+function flock_put_contents($filename, $data, $mode = "wb")
+{
+ $fp = fopen( $filename, $mode );
+ if( $fp && flock( $fp, LOCK_EX ) )
+ {
+ fwrite( $fp, $data );
+ flock($fp, LOCK_UN);
+ }
+ fclose( $fp );
+}
+
+
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|