/** * Loads an array from the given file path. * * This method uses file locks and is therefore synchornization-safe. * This method will block until a file lock is acquired. * * @param string $fpath file path * * @return array array loaded from file path, or an empty array if fpath * does not exist */ public static function loadArray($fpath) { if (!file_exists($fpath)) { return array(); } $handle = fopen($fpath, 'r'); if (!$handle) { throw Exception('Unable to open file: ' . $fpath); } if (!flock($handle, LOCK_SH)) { throw Exception('Unable to get lock on ' . $fpath); } $content = fread($handle, FileUtil::_fsize($fpath)); $arr = unserialize($content); if (!is_array($arr)) { return array(); } flock($handle, LOCK_UN); fclose($handle); return $arr; }