com web/rmtools: Locking reads: include/Branch.php

From: Date: Fri, 15 Sep 2017 12:17:05 +0000
Subject: com web/rmtools: Locking reads: include/Branch.php
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-26397@lists.php.net to get a copy of this message
Commit: 7886bfcb221e56c2f53491eaa510aadad5ffa9bc Author: Anatol Belski <ab@php.net> 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;

« previous php.webmaster (#26397) next »