Author: robux4
Date: 2004-11-16 19:16:25 +0300 (Tue, 16 Nov 2004)
New Revision: 788
Modified:
trunk/packs.matroska.org/data/download.php
trunk/packs.matroska.org/data/helper.php
trunk/packs.matroska.org/data/index.php.de
trunk/packs.matroska.org/data/index.php.en
trunk/packs.matroska.org/data/index.php.fr
trunk/packs.matroska.org/data/index.php.nl
trunk/packs.matroska.org/data/index.php.pt
trunk/packs.matroska.org/data/ircstats.php
trunk/packs.matroska.org/data/showlog.php
Log:
only lock the file on writing
it should be safe now, only a few clicks will be missed
Modified: trunk/packs.matroska.org/data/download.php
===================================================================
--- trunk/packs.matroska.org/data/download.php 2004-11-16 15:50:36 UTC (rev 787)
+++ trunk/packs.matroska.org/data/download.php 2004-11-16 16:16:25 UTC (rev 788)
@@ -26,14 +26,24 @@
}
// Save Download Stats
- $download = unserialize(safe_read_file($logfilename));
-
- // Make sure we opened the logfile correctly, otherwise we're gonna trash it
- if (count($download) != 0)
+ $return = "";
+ $fp = fopen($logfilename,"r+");
+ if($fp)
{
- $download[$version][$_REQUEST["id"]]++;
- safe_write_file($logfilename,serialize($download));
- }
+ if (flock($fp, LOCK_EX)) { // exclusive lock
+ $download = unserialize(fread($fp, filesize($file)));
+
+ // Make sure we opened the logfile correctly, otherwise we're gonna trash it
+ if (count($download) != 0)
+ {
+ fseek($fp, 0);
+ $download[$version][$_REQUEST["id"]]++;
+ fwrite($fp, serialize($download));
+ }
+ flock($fp, LOCK_UN);
+ }
+ fclose($fp);
+ }
// Create New Header
header("Location: $link");
Modified: trunk/packs.matroska.org/data/helper.php
===================================================================
--- trunk/packs.matroska.org/data/helper.php 2004-11-16 15:50:36 UTC (rev 787)
+++ trunk/packs.matroska.org/data/helper.php 2004-11-16 16:16:25 UTC (rev 788)
@@ -64,34 +64,15 @@
echo number_format($filesize[$packversion][$packname], 0, '.', '\'') . " Bytes";
}
- function safe_read_file($file)
+ function read_file($file)
{
$return = "";
$fp = fopen($file,"r");
if($fp)
{
- if (flock($fp, LOCK_EX)) { // exclusive lock
- $return = fread($fp, filesize($file));
- flock($fp, LOCK_UN);
- }
+ $return = fread($fp, filesize($file));
fclose($fp);
}
return $return;
}
-
- function safe_write_file($file,$data)
- {
- if(count($data))
- {
- $fp = fopen($file, "w");
- if($fp)
- {
- if (flock($fp, LOCK_EX)) { // exclusive lock
- fwrite($fp, $data);
- flock($fp, LOCK_UN);
- }
- fclose($fp);
- }
- }
- }
?>
Modified: trunk/packs.matroska.org/data/index.php.de
===================================================================
--- trunk/packs.matroska.org/data/index.php.de 2004-11-16 15:50:36 UTC (rev 787)
+++ trunk/packs.matroska.org/data/index.php.de 2004-11-16 16:16:25 UTC (rev 788)
@@ -1,6 +1,6 @@
<?php
include("helper.php");
- $download = unserialize(safe_read_file('logs.txt'));
+ $download = unserialize(read_file('logs.txt'));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
Modified: trunk/packs.matroska.org/data/index.php.en
===================================================================
--- trunk/packs.matroska.org/data/index.php.en 2004-11-16 15:50:36 UTC (rev 787)
+++ trunk/packs.matroska.org/data/index.php.en 2004-11-16 16:16:25 UTC (rev 788)
@@ -1,6 +1,6 @@
<?php
include("helper.php");
- $download = unserialize(safe_read_file('logs.txt'));
+ $download = unserialize(read_file('logs.txt'));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
Modified: trunk/packs.matroska.org/data/index.php.fr
===================================================================
--- trunk/packs.matroska.org/data/index.php.fr 2004-11-16 15:50:36 UTC (rev 787)
+++ trunk/packs.matroska.org/data/index.php.fr 2004-11-16 16:16:25 UTC (rev 788)
@@ -1,6 +1,6 @@
<?php
include("helper.php");
- $download = unserialize(safe_read_file('logs.txt'));
+ $download = unserialize(read_file('logs.txt'));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
Modified: trunk/packs.matroska.org/data/index.php.nl
===================================================================
--- trunk/packs.matroska.org/data/index.php.nl 2004-11-16 15:50:36 UTC (rev 787)
+++ trunk/packs.matroska.org/data/index.php.nl 2004-11-16 16:16:25 UTC (rev 788)
@@ -1,6 +1,6 @@
<?php
include("helper.php");
- $download = unserialize(safe_read_file('logs.txt'));
+ $download = unserialize(read_file('logs.txt'));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
Modified: trunk/packs.matroska.org/data/index.php.pt
===================================================================
--- trunk/packs.matroska.org/data/index.php.pt 2004-11-16 15:50:36 UTC (rev 787)
+++ trunk/packs.matroska.org/data/index.php.pt 2004-11-16 16:16:25 UTC (rev 788)
@@ -1,6 +1,6 @@
<?php
include("helper.php");
- $download = unserialize(safe_read_file('logs.txt'));
+ $download = unserialize(read_file('logs.txt'));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
Modified: trunk/packs.matroska.org/data/ircstats.php
===================================================================
--- trunk/packs.matroska.org/data/ircstats.php 2004-11-16 15:50:36 UTC (rev 787)
+++ trunk/packs.matroska.org/data/ircstats.php 2004-11-16 16:16:25 UTC (rev 788)
@@ -4,7 +4,7 @@
$logfilename = "logs.txt";
include("helper.php");
-$download = unserialize(safe_read_file($logfilename));
+$download = unserialize(read_file($logfilename));
$totalcount = 0;
$totalsize = 0;
Modified: trunk/packs.matroska.org/data/showlog.php
===================================================================
--- trunk/packs.matroska.org/data/showlog.php 2004-11-16 15:50:36 UTC (rev 787)
+++ trunk/packs.matroska.org/data/showlog.php 2004-11-16 16:16:25 UTC (rev 788)
@@ -3,7 +3,7 @@
<pre>
<?php
$logfilename = "logs.txt";
-$download = unserialize(safe_read_file($logfilename));
+$download = unserialize(read_file($logfilename));
print_r($download);
?>
</pre>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.