realFileName = $fileName; $this->tmpFileName = $fileName . '.tmp.' . mt_rand( 0, 0x7fffffff ); $this->handle = dba_open( $this->tmpFileName, 'n', 'cdb_make' ); if ( !$this->handle ) { throw new Exception( 'Unable to open CDB file for write "' . $fileName . '"' ); } } public function set( $key, $value ) { return dba_insert( $key, $value, $this->handle ); } /** * @throws Exception */ public function close() { if ( isset( $this->handle ) ) { dba_close( $this->handle ); } if ( $this->isWindows() ) { unlink( $this->realFileName ); } if ( !rename( $this->tmpFileName, $this->realFileName ) ) { throw new Exception( 'Unable to move the new CDB file into place.' ); } unset( $this->handle ); } }