Commit:    7886bfcb221e56c2f53491eaa510aadad5ffa9bc
Author:    Anatol Belski <[email protected]>         Fri, 15 Sep 2017 14:17:05 +0200
Parents:   4a58be2b90eb0df8ed9ab282adf58847d8c09fa3
Branches:  master

Link:       
http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=7886bfcb221e56c2f53491eaa510aadad5ffa9bc

Log:
Locking reads

Changed paths:
  M  include/Branch.php


Diff:
diff --git a/include/Branch.php b/include/Branch.php
index ad95daf..91ba18f 100644
--- a/include/Branch.php
+++ b/include/Branch.php
@@ -30,7 +30,18 @@ class Branch {
        protected function readData()
        {
                if (file_exists($this->db_path)) {
-                       $data = json_decode(file_get_contents($this->db_path));
+                       $fd = fopen($this->db_path, "rb");
+                       if (!$fd) {
+                               throw new \Exception("Failed to open 
{$this->db_path}.");
+                       }
+                       flock($fd, LOCK_SH);
+                       $j = "";
+                       while(!feof($fd)) {
+                               $j .= fread($fd, 1024);
+                       }
+                       $data = json_decode($j);
+                       flock($fd, LOCK_UN);
+                       fclose($fd);
                } else {
                        $data = new \StdClass;
                        $data->revision_last = NULL;


--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to