ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
getID3_cached_dbm Class Reference

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

+ Inheritance diagram for getID3_cached_dbm:
+ Collaboration diagram for getID3_cached_dbm:

Public Member Functions

 getID3_cached_dbm ($cache_type, $dbm_filename, $lock_filename)
 
 __destruct ()
 
 clear_cache ()
 
 analyze ($filename)
 
 getID3_cached_dbm ($cache_type, $dbm_filename, $lock_filename)
 
 __destruct ()
 
 clear_cache ()
 
 analyze ($filename)
 
- Public Member Functions inherited from getID3
 getID3 ()
 
 setOption ($optArray)
 
 analyze ($filename)
 
 error ($message)
 
 warning ($message)
 
 CleanUp ()
 
 GetFileFormatArray ()
 
 GetFileFormat (&$filedata, $filename='')
 
 CharConvert (&$array, $encoding)
 
 HandleAllTags ()
 
 getHashdata ($algorithm)
 
 ChannelsBitratePlaytimeCalculations ()
 
 CalculateCompressionRatioVideo ()
 
 CalculateCompressionRatioAudio ()
 
 CalculateReplayGain ()
 
 ProcessAudioStreams ()
 
 getid3_tempnam ()
 
 __construct ()
 
 version ()
 
 fread_buffer_size ()
 
 setOption ($optArray)
 
 openfile ($filename, $filesize=null)
 
 analyze ($filename, $filesize=null, $original_filename='')
 
 error ($message)
 
 warning ($message)
 
 GetFileFormatArray ()
 
 GetFileFormat (&$filedata, $filename='')
 
 CharConvert (&$array, $encoding)
 
 HandleAllTags ()
 
 getHashdata ($algorithm)
 
 ChannelsBitratePlaytimeCalculations ()
 
 CalculateCompressionRatioVideo ()
 
 CalculateCompressionRatioAudio ()
 
 CalculateReplayGain ()
 
 ProcessAudioStreams ()
 
 getid3_tempnam ()
 
 include_module ($name)
 

Additional Inherited Members

- Data Fields inherited from getID3
 $encoding = 'ISO-8859-1'
 
 $encoding_id3v1 = 'ISO-8859-1'
 
 $tempdir = '*'
 
 $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_md5_data = false
 
 $option_md5_data_source = false
 
 $option_sha1_data = false
 
 $option_max_2gb_check = true
 
 $filename
 
 $option_save_attachments = true
 
 $option_fread_buffer_size = 32768
 
 $fp
 
 $info
 
 $memory_limit = 0
 
const VERSION = '1.9.10-20150914'
 
const FREAD_BUFFER_SIZE = 32768
 
const ATTACHMENTS_NONE = false
 
const ATTACHMENTS_INLINE = true
 
- Protected Attributes inherited from getID3
 $startup_error = ''
 
 $startup_warning = ''
 

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

Definition at line 72 of file extension.cache.dbm.php.

Constructor & Destructor Documentation

◆ __destruct() [1/2]

getID3_cached_dbm::__destruct ( )

Definition at line 155 of file extension.cache.dbm.php.

155  {
156 
157  // Close dbm file
158  @dba_close($this->dba);
159 
160  // Release exclusive lock
161  @flock($this->lock, LOCK_UN);
162 
163  // Close lock file
164  @fclose($this->lock);
165  }

◆ __destruct() [2/2]

getID3_cached_dbm::__destruct ( )

Definition at line 145 of file extension.cache.dbm.php.

145  {
146 
147  // Close dbm file
148  dba_close($this->dba);
149 
150  // Release exclusive lock
151  flock($this->lock, LOCK_UN);
152 
153  // Close lock file
154  fclose($this->lock);
155  }

Member Function Documentation

◆ analyze() [1/2]

getID3_cached_dbm::analyze (   $filename)

Definition at line 182 of file extension.cache.dbm.php.

References getID3\$filename, and $result.

182  {
183 
184  if (file_exists($filename)) {
185 
186  // Calc key filename::mod_time::size - should be unique
187  $key = $filename.'::'.filemtime($filename).'::'.filesize($filename);
188 
189  // Loopup key
190  $result = dba_fetch($key, $this->dba);
191 
192  // Hit
193  if ($result !== false) {
194  return unserialize($result);
195  }
196  }
197 
198  // Miss
199  $result = parent::analyze($filename);
200 
201  // Save result
202  if (file_exists($filename)) {
203  dba_insert($key, serialize($result), $this->dba);
204  }
205 
206  return $result;
207  }
$result
$filename
Definition: getid3.php:46

◆ analyze() [2/2]

getID3_cached_dbm::analyze (   $filename)

Definition at line 192 of file extension.cache.dbm.php.

References getID3\$filename, and $result.

192  {
193 
194  if (file_exists($filename)) {
195 
196  // Calc key filename::mod_time::size - should be unique
197  $key = $filename . '::' . filemtime($filename) . '::' . filesize($filename);
198 
199  // Loopup key
200  $result = dba_fetch($key, $this->dba);
201 
202  // Hit
203  if ($result !== false) {
204  return unserialize($result);
205  }
206  }
207 
208  // Miss
209  $result = parent::analyze($filename);
210 
211  // Save result
212  if (file_exists($filename)) {
213  dba_insert($key, serialize($result), $this->dba);
214  }
215 
216  return $result;
217  }
$result
$filename
Definition: getid3.php:46

◆ clear_cache() [1/2]

getID3_cached_dbm::clear_cache ( )

Definition at line 160 of file extension.cache.dbm.php.

References getID3\VERSION.

160  {
161 
162  // Close dbm file
163  dba_close($this->dba);
164 
165  // Create new dbm file
166  $this->dba = dba_open($this->dbm_filename, 'n', $this->cache_type);
167 
168  if (!$this->dba) {
169  throw new Exception('failed to clear cache/recreate dbm file: '.$this->dbm_filename);
170  }
171 
172  // Insert getID3 version number
173  dba_insert(getID3::VERSION, getID3::VERSION, $this->dba);
174 
175  // Re-register shutdown function
176  register_shutdown_function(array($this, '__destruct'));
177  }
const VERSION
Definition: getid3.php:112

◆ clear_cache() [2/2]

getID3_cached_dbm::clear_cache ( )

Definition at line 170 of file extension.cache.dbm.php.

References GETID3_VERSION.

Referenced by getID3_cached_dbm().

170  {
171 
172  // Close dbm file
173  dba_close($this->dba);
174 
175  // Create new dbm file
176  $this->dba = dba_open($this->dbm_filename, 'n', $this->cache_type);
177 
178  if (!$this->dba) {
179  die('failed to clear cache/recreate dbm file: ' . $this->dbm_filename);
180  }
181 
182  // Insert getID3 version number
183  dba_insert(GETID3_VERSION, GETID3_VERSION, $this->dba);
184 
185  // Reregister shutdown function
186  register_shutdown_function(array($this, '__destruct'));
187  }
const GETID3_VERSION
getID3() by James Heinrich info@getid3.org //
Definition: getid3.php:13
+ Here is the caller graph for this function:

◆ getID3_cached_dbm() [1/2]

getID3_cached_dbm::getID3_cached_dbm (   $cache_type,
  $dbm_filename,
  $lock_filename 
)

Definition at line 76 of file extension.cache.dbm.php.

References clear_cache(), and GETID3_VERSION.

76  {
77 
78  // Check for dba extension
79  if (!extension_loaded('dba')) {
80  die('PHP is not compiled with dba support, required to use DBM style cache.');
81  }
82 
83  // Check for specific dba driver
84  if (function_exists('dba_handlers')) { // PHP 4.3.0+
85  if (!in_array('db3', dba_handlers())) {
86  die('PHP is not compiled --with '.$cache_type.' support, required to use DBM style cache.');
87  }
88  }
89  else { // PHP <= 4.2.3
90  ob_start(); // nasty, buy the only way to check...
91  phpinfo();
92  $contents = ob_get_contents();
93  ob_end_clean();
94  if (!strstr($contents, $cache_type)) {
95  die('PHP is not compiled --with '.$cache_type.' support, required to use DBM style cache.');
96  }
97  }
98 
99  // Create lock file if needed
100  if (!file_exists($lock_filename)) {
101  if (!touch($lock_filename)) {
102  die('failed to create lock file: ' . $lock_filename);
103  }
104  }
105 
106  // Open lock file for writing
107  if (!is_writeable($lock_filename)) {
108  die('lock file: ' . $lock_filename . ' is not writable');
109  }
110  $this->lock = fopen($lock_filename, 'w');
111 
112  // Acquire exclusive write lock to lock file
113  flock($this->lock, LOCK_EX);
114 
115  // Create dbm-file if needed
116  if (!file_exists($dbm_filename)) {
117  if (!touch($dbm_filename)) {
118  die('failed to create dbm file: ' . $dbm_filename);
119  }
120  }
121 
122  // Try to open dbm file for writing
123  $this->dba = @dba_open($dbm_filename, 'w', $cache_type);
124  if (!$this->dba) {
125 
126  // Failed - create new dbm file
127  $this->dba = dba_open($dbm_filename, 'n', $cache_type);
128 
129  if (!$this->dba) {
130  die('failed to create dbm file: ' . $dbm_filename);
131  }
132 
133  // Insert getID3 version number
134  dba_insert(GETID3_VERSION, GETID3_VERSION, $this->dba);
135  }
136 
137  // Init misc values
138  $this->cache_type = $cache_type;
139  $this->dbm_filename = $dbm_filename;
140 
141  // Register destructor
142  register_shutdown_function(array($this, '__destruct'));
143 
144  // Check version number and clear cache if changed
145  if (dba_fetch(GETID3_VERSION, $this->dba) != GETID3_VERSION) {
146  $this->clear_cache();
147  }
148 
149  parent::getID3();
150  }
const GETID3_VERSION
getID3() by James Heinrich info@getid3.org //
Definition: getid3.php:13
+ Here is the call graph for this function:

◆ getID3_cached_dbm() [2/2]

getID3_cached_dbm::getID3_cached_dbm (   $cache_type,
  $dbm_filename,
  $lock_filename 
)

Definition at line 77 of file extension.cache.dbm.php.

References clear_cache(), and getID3\VERSION.

77  {
78 
79  // Check for dba extension
80  if (!extension_loaded('dba')) {
81  throw new Exception('PHP is not compiled with dba support, required to use DBM style cache.');
82  }
83 
84  // Check for specific dba driver
85  if (!function_exists('dba_handlers') || !in_array($cache_type, dba_handlers())) {
86  throw new Exception('PHP is not compiled --with '.$cache_type.' support, required to use DBM style cache.');
87  }
88 
89  // Create lock file if needed
90  if (!file_exists($lock_filename)) {
91  if (!touch($lock_filename)) {
92  throw new Exception('failed to create lock file: '.$lock_filename);
93  }
94  }
95 
96  // Open lock file for writing
97  if (!is_writeable($lock_filename)) {
98  throw new Exception('lock file: '.$lock_filename.' is not writable');
99  }
100  $this->lock = fopen($lock_filename, 'w');
101 
102  // Acquire exclusive write lock to lock file
103  flock($this->lock, LOCK_EX);
104 
105  // Create dbm-file if needed
106  if (!file_exists($dbm_filename)) {
107  if (!touch($dbm_filename)) {
108  throw new Exception('failed to create dbm file: '.$dbm_filename);
109  }
110  }
111 
112  // Try to open dbm file for writing
113  $this->dba = dba_open($dbm_filename, 'w', $cache_type);
114  if (!$this->dba) {
115 
116  // Failed - create new dbm file
117  $this->dba = dba_open($dbm_filename, 'n', $cache_type);
118 
119  if (!$this->dba) {
120  throw new Exception('failed to create dbm file: '.$dbm_filename);
121  }
122 
123  // Insert getID3 version number
124  dba_insert(getID3::VERSION, getID3::VERSION, $this->dba);
125  }
126 
127  // Init misc values
128  $this->cache_type = $cache_type;
129  $this->dbm_filename = $dbm_filename;
130 
131  // Register destructor
132  register_shutdown_function(array($this, '__destruct'));
133 
134  // Check version number and clear cache if changed
135  if (dba_fetch(getID3::VERSION, $this->dba) != getID3::VERSION) {
136  $this->clear_cache();
137  }
138 
139  parent::__construct();
140  }
const VERSION
Definition: getid3.php:112
+ Here is the call graph for this function:

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