protected function _lockFile($sFilePath, $sIdent, $iLockMode = LOCK_EX)
    {
        $rHandle = isset($this->_aLockedFileHandles[$iLockMode][$sIdent]) ? $this->_aLockedFileHandles[$iLockMode][$sIdent] : null;
        if ($rHandle === null) {
            $blLocked = false;
            $rHandle = @fopen($sFilePath, "a+");

            if ($rHandle !== false) {
                if (flock($rHandle, $iLockMode | LOCK_NB)) {
                    if ($iLockMode === LOCK_EX) {
                        // truncate file
                        $blLocked = ftruncate($rHandle, 0);
                    } else {
                        // move to a start position
                        $blLocked = fseek($rHandle, 0) === 0;
                    }
                }

                // on failure - closing and setting false..
                if (!$blLocked) {
                    fclose($rHandle);
                    $rHandle = false;
                }
            }

            // in case system does not support file locking
            if (!$blLocked && $iLockMode === LOCK_EX) {
                // clearing on first call
                if (count($this->_aLockedFileHandles) == 0) {
                    clearstatcache();
                }

                // start a blank file to inform other processes we are dealing with it.
                if (!(file_exists($sFilePath) && !filesize($sFilePath) && abs(time() - filectime($sFilePath) < 40))) {
                    $rHandle = @fopen($sFilePath, "w");
                }
            }

            $this->_aLockedFileHandles[$iLockMode][$sIdent] = $rHandle;
        }

        return $rHandle;
    }