htmlsc(basename($filename)));
}
}
+
+/**
+ * Lock-enabled file_get_contents
+ *
+ * Require: PHP5+
+ */
+function pkwk_file_get_contents($filename) {
+ if (! file_exists($filename)) {
+ return false;
+ }
+ $fp = fopen($filename, 'rb');
+ flock($fp, LOCK_SH);
+ $file = file_get_contents($filename);
+ flock($fp, LOCK_UN);
+ return $file;
+}
// Cache management
$data_updated = true;
$cache_filepath = CACHE_DIR . encode($page) . '.bugtrack';
- $json_cached = file_get_contents($cache_filepath);
+ $json_cached = pkwk_file_get_contents($cache_filepath);
if ($json_cached) {
$wrapdata = json_decode($json_cached);
if (is_object($wrapdata)) {
}
$json = array('refreshed_at'=>$refreshed_at, 'pages'=>$data, 'version'=>$cache_format_version);
$cache_body = json_encode($json, JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES);
- file_put_contents($cache_filepath, $cache_body);
+ file_put_contents($cache_filepath, $cache_body, LOCK_EX);
}
}
$table = array();