public static function lockFile($filePath, $is_write_lock, $is_blocking)
    {
        global $globals;
        
        # This creates the file if it doesnt exist.
        # we have to assign the file to a global variable, otherwise the file lock will be released
        # as soon as we exit this function.
        # This MUST be a+ instead of w or w+ as using w will result in the file being wiped.
        $globals['file_locks'][$filePath] = fopen($filePath, 'a+');
        
        $lock_params = 0;
        
        if ($is_write_lock)
        {
            $lock_params =  $lock_params | LOCK_EX;
        }
        else
        {
            # read lock = shared lock
            $lock_params = $lock_params | LOCK_SH;
        }
        
        if (!$is_blocking)
        {
            $lock_params = $lock_params | LOCK_NB;
        }
        
        $result = flock($globals['file_locks'][$filePath], $lock_params);
        
        return $result;
    }