ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
GetId3\Extension\Cache\Dbm Class Reference

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //. More...

+ Inheritance diagram for GetId3\Extension\Cache\Dbm:
+ Collaboration diagram for GetId3\Extension\Cache\Dbm:

Public Member Functions

 __construct ($cache_type, $dbm_filename, $lock_filename)
 public: constructor - see top of this file for cache type and cache_options More...
 
 __destruct ()
 
 clear_cache ()
 clear cache More...
 
 analyze ($filename)
 analyze file More...
 
- Public Member Functions inherited from GetId3\GetId3Core
 __construct ()
 public: constructor More...
 
 version ()
 
 fread_buffer_size ()
 
 setOption ($optArray)
 public: setOption More...
 
 openfile ($filename)
 
 analyze ($filename)
 public: analyze file More...
 
 GetFileFormatArray ()
 @staticvar array $format_info More...
 
 GetFileFormat (&$filedata, $filename='')
 
 CharConvert (&$array, $encoding)
 
 HandleAllTags ()
 @staticvar array $tags More...
 
 getHashdata ($algorithm)
 
 ChannelsBitratePlaytimeCalculations ()
 
 CalculateCompressionRatioVideo ()
 
 CalculateCompressionRatioAudio ()
 
 CalculateReplayGain ()
 
 ProcessAudioStreams ()
 
 GetId3_tempnam ()
 

Additional Inherited Members

- Static Public Member Functions inherited from GetId3\GetId3Core
static getHelperAppsDir ()
 
static getTempDir ()
 
static environmentIsWindows ()
 
static getIncludePath ()
 
- Data Fields inherited from GetId3\GetId3Core
 $encoding = 'UTF-8'
 
 $encoding_id3v1 = 'ISO-8859-1'
 
 $option_tag_id3v1 = true
 
 $option_tag_id3v2 = true
 
 $option_tag_lyrics3 = true
 
 $option_tag_apetag = true
 
 $option_tags_process = true
 
 $option_tags_html = true
 
 $option_extra_info = true
 
 $option_save_attachments = true
 
 $option_md5_data = false
 
 $option_md5_data_source = false
 
 $option_sha1_data = false
 
 $option_max_2gb_check = null
 
 $option_fread_buffer_size = 32768
 
 $filename
 
 $fp
 
 $info
 
 $tempdir
 
const VERSION = '1.9.4-20120530'
 
const FREAD_BUFFER_SIZE = 32768
 
const ATTACHMENTS_NONE = false
 
const ATTACHMENTS_INLINE = true
 
- Protected Member Functions inherited from GetId3\GetId3Core
 setHelperAppsDir ()
 
- Protected Attributes inherited from GetId3\GetId3Core
 $startup_error = ''
 
 $startup_warning = ''
 
 $memory_limit = 0
 
- Static Protected Attributes inherited from GetId3\GetId3Core
static $TempDir
 
static $IncludePath
 
static $EnvironmentIsWindows
 
static $HelperAppsDir
 

Detailed Description

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //.

This is a caching extension for GetId3(). It works the exact same way as the GetId3 class, but return cached information very fast

Example:

Normal GetId3 usage (example):

require_once 'getid3/getid3.php'; $getID3 = new GetId3; $getID3->encoding = 'UTF-8'; $info1 = $getID3->analyze('file1.flac'); $info2 = $getID3->analyze('file2.wv');

GetId3_cached usage:

require_once 'getid3/getid3.php'; require_once 'getid3/getid3/extension.cache.dbm.php'; $getID3 = new GetId3_cached('db3', '/tmp/getid3_cache.dbm', '/tmp/getid3_cache.lock'); $getID3->encoding = 'UTF-8'; $info1 = $getID3->analyze('file1.flac'); $info2 = $getID3->analyze('file2.wv');

Supported Cache Types

SQL Databases: (use extension.cache.mysql)

cache_type cache_options

mysql host, database, username, password

DBM-Style Databases: (this extension)

cache_type cache_options

gdbm dbm_filename, lock_filename ndbm dbm_filename, lock_filename db2 dbm_filename, lock_filename db3 dbm_filename, lock_filename db4 dbm_filename, lock_filename (PHP5 required)

PHP must have write access to both dbm_filename and lock_filename.

Recommended Cache Types

Infrequent updates, many reads any DBM Frequent updates mysql

Author
James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g
Allan Hansen <ahØartemis*dk> http://www.getid3.org

Definition at line 83 of file Dbm.php.

Constructor & Destructor Documentation

◆ __construct()

GetId3\Extension\Cache\Dbm::__construct (   $cache_type,
  $dbm_filename,
  $lock_filename 
)

public: constructor - see top of this file for cache type and cache_options

Parameters
type$cache_type
type$dbm_filename
type$lock_filename
Exceptions
Exception

Definition at line 94 of file Dbm.php.

95 {
96 // Check for dba extension
97 if (!extension_loaded('dba')) {
98 throw new DefaultException('PHP is not compiled with dba support, required to use DBM style cache.');
99 }
100
101 // Check for specific dba driver
102 if (!function_exists('dba_handlers') || !in_array($cache_type, dba_handlers())) {
103 throw new DefaultException('PHP is not compiled --with '.$cache_type.' support, required to use DBM style cache.');
104 }
105
106 // Create lock file if needed
107 if (!file_exists($lock_filename)) {
108 if (!touch($lock_filename)) {
109 throw new DefaultException('failed to create lock file: '.$lock_filename);
110 }
111 }
112
113 // Open lock file for writing
114 if (!is_writeable($lock_filename)) {
115 throw new DefaultException('lock file: '.$lock_filename.' is not writable');
116 }
117 $this->lock = fopen($lock_filename, 'w');
118
119 // Acquire exclusive write lock to lock file
120 flock($this->lock, LOCK_EX);
121
122 // Create dbm-file if needed
123 if (!file_exists($dbm_filename)) {
124 if (!touch($dbm_filename)) {
125 throw new DefaultException('failed to create dbm file: '.$dbm_filename);
126 }
127 }
128
129 // Try to open dbm file for writing
130 $this->dba = dba_open($dbm_filename, 'w', $cache_type);
131 if (!$this->dba) {
132
133 // Failed - create new dbm file
134 $this->dba = dba_open($dbm_filename, 'n', $cache_type);
135
136 if (!$this->dba) {
137 throw new DefaultException('failed to create dbm file: '.$dbm_filename);
138 }
139
140 // Insert GetId3 version number
141 dba_insert(GetId3Core::VERSION, GetId3Core::VERSION, $this->dba);
142 }
143
144 // Init misc values
145 $this->cache_type = $cache_type;
146 $this->dbm_filename = $dbm_filename;
147
148 // Register destructor
149 register_shutdown_function(array($this, '__destruct'));
150
151 // Check version number and clear cache if changed
152 if (dba_fetch(GetId3Core::VERSION, $this->dba) != GetId3Core::VERSION) {
153 $this->clear_cache();
154 }
155
156 parent::__construct();
157 }
clear_cache()
clear cache
Definition: Dbm.php:179

References GetId3\Extension\Cache\Dbm\clear_cache(), and GetId3\GetId3Core\VERSION.

+ Here is the call graph for this function:

◆ __destruct()

GetId3\Extension\Cache\Dbm::__destruct ( )

Definition at line 162 of file Dbm.php.

163 {
164 // Close dbm file
165 dba_close($this->dba);
166
167 // Release exclusive lock
168 flock($this->lock, LOCK_UN);
169
170 // Close lock file
171 fclose($this->lock);
172 }

Member Function Documentation

◆ analyze()

GetId3\Extension\Cache\Dbm::analyze (   $filename)

analyze file

Parameters
type$filename
Returns
type

Reimplemented from GetId3\GetId3Core.

Definition at line 204 of file Dbm.php.

205 {
206 if (file_exists($filename)) {
207
208 // Calc key filename::mod_time::size - should be unique
209 $key = $filename.'::'.filemtime($filename).'::'.filesize($filename);
210
211 // Loopup key
212 $result = dba_fetch($key, $this->dba);
213
214 // Hit
215 if ($result !== false) {
216 return unserialize($result);
217 }
218 }
219
220 // Miss
221 $result = parent::analyze($filename);
222
223 // Save result
224 if (file_exists($filename)) {
225 dba_insert($key, serialize($result), $this->dba);
226 }
227
228 return $result;
229 }
$result

References GetId3\GetId3Core\$filename, and $result.

◆ clear_cache()

GetId3\Extension\Cache\Dbm::clear_cache ( )

clear cache

Exceptions
Exception

Definition at line 179 of file Dbm.php.

180 {
181 // Close dbm file
182 dba_close($this->dba);
183
184 // Create new dbm file
185 $this->dba = dba_open($this->dbm_filename, 'n', $this->cache_type);
186
187 if (!$this->dba) {
188 throw new DefaultException('failed to clear cache/recreate dbm file: '.$this->dbm_filename);
189 }
190
191 // Insert GetId3 version number
192 dba_insert(GetId3Core::VERSION, GetId3Core::VERSION, $this->dba);
193
194 // Re-register shutdown function
195 register_shutdown_function(array($this, '__destruct'));
196 }

References GetId3\GetId3Core\VERSION.

Referenced by GetId3\Extension\Cache\Dbm\__construct().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: