28 $this->handle = dba_open( $fileName,
'r-',
'cdb' );
29 if ( !$this->handle ) {
30 throw new CdbException(
'Unable to open CDB file "' . $fileName .
'"' );
35 if ( isset( $this->handle ) ) {
36 dba_close( $this->handle );
38 unset( $this->handle );
41 public function get( $key ) {
42 return dba_fetch( $key, $this->handle );
51 $this->realFileName = $fileName;
52 $this->tmpFileName = $fileName .
'.tmp.' . mt_rand( 0, 0x7fffffff );
53 $this->handle = dba_open( $this->tmpFileName,
'n',
'cdb_make' );
54 if ( !$this->handle ) {
55 throw new CdbException(
'Unable to open CDB file for write "' . $fileName .
'"' );
59 public function set( $key,
$value ) {
60 return dba_insert( $key,
$value, $this->handle );
64 if ( isset( $this->handle ) ) {
65 dba_close( $this->handle );
68 unlink( $this->realFileName );
70 if ( !rename( $this->tmpFileName, $this->realFileName ) ) {
71 throw new CdbException(
'Unable to move the new CDB file into place.' );
73 unset( $this->handle );