private function safelyWriteData($path, $mode, $data)
    {
        $fp = fopen($path, $mode);
        $retries = 0;

        if (empty($fp)) {
            return false;
        }

        do {
            if ($retries > 0) {
                usleep(static::MS_BETWEEN_RETRIES * 1000);
            }

            $retries++;
        } while (!flock($fp, LOCK_EX) && $retries <= static::MAX_RETRIES);

        if ($retries == static::MAX_RETRIES) {
            return false;
        }


        fwrite($fp, "$data\n");

        flock($fp, LOCK_UN);
        fclose($fp);

        return true;
    }
private function safelyWriteData($path, $mode, $data)
    {
        $fp = fopen($path, $mode);
        $retries = 0;

        if (empty($fp)) {
            return false;
        }

        do {
            if ($retries > 0) {
                usleep(static::MS_BETWEEN_RETRIES * 1000);
            }

            $retries++;
        } while (!flock($fp, LOCK_EX) && $retries <= static::MAX_RETRIES);

        if ($retries == static::MAX_RETRIES) {
            return false;
        }


        fwrite($fp, "$data\n");

        flock($fp, LOCK_UN);
        fclose($fp);

        return true;
    }
private function safelyWriteData ( $ path , $ mode , $ data ) { $ fp = fopen ( $ path , $ mode ) ; $ retries = 0 ; if ( empty ( $ fp ) ) { return false ; } do { if ( $ retries > 0 ) { usleep ( static :: MS_BETWEEN_RETRIES * 1000 ) ; } $ retries ++ ; } while ( ! flock ( $ fp , LOCK_EX ) && $ retries <= static :: MAX_RETRIES ) ; if ( $ retries == static :: MAX_RETRIES ) { return false ; } fwrite ( $ fp , "$data\n" ) ; flock ( $ fp , LOCK_UN ) ; fclose ( $ fp ) ; return true ; }
Safely write data to a file

@param string $path
@param string $mode
@param string $data

@return boolean
Safely write data to a file