|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-03-02 03:11 UTC] mwilmes at wilminator dot com
Description:
------------
A function catalogs the id3 tags of files in a directory. Not all files are mp3 files. The loop uses a dir() object to get the filenames.
Seems to work fine for the first few files, then this error appears:
Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 1852404086 bytes) in /home/mwilmes/www/mp3play/index.php on line 13
MP3 File size: 5,812,461 bytes
Code:
$id3info = id3_get_tag($filename);
Error follows around even after the 'offending' mp3 file is removed from the directory.
Error exists even after the non-mp3 file is removed.
php.ini set to allow 24M memory for script execution
uses gd, sqlite, mysql, and id3 v. 0.2
Reproduce code:
---------------
function catalogMP3File($filename) {
$id3info = id3_get_tag($filename);
if ($id3info && is_numeric($id3info['genre'])) {
$id3info['genre'] = "({$id3info['genre']}) ".id3_get_genre_name($id3info['genre']);}
return $id3info;
}
function findMP3Files($path,$recurse=false) {
$path=realpath($path).'/';
$mp3files=array();
$dir=dir($path);
while($file=$dir->read()) {
if ($file!='.' && $file!='..') {
$filename=$path.$file;
if (is_dir($filename)) {
if ($recurse) {
$result=findMP3Files($filename,$recurse);
if ($result) { $mp3files+=$result;}
}
}
else {
$id3info=catalogMP3File($filename);
if($id3info) {$mp3files[$filename]=$id3info;
}
}
}
}
return $mp3files;
}
Expected result:
----------------
When calling findMP3Files, I should get an array of id3 tag results with the keys being the names of the files the data was collected from.
Actual result:
--------------
System attempts to allocate 1.8GB RAM and fails.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 01:00:01 2025 UTC |
I am currently using the idea from lacent and got it to work like this: // allowed id3 versions // $allowedid3s[]=0; // ID3_BEST // $allowedid3s[]=1; // ID3_V1_0 // $allowedid3s[]=3; // ID3_V1_1 // $allowedid3s[]=4; // ID3_V2_1 // $allowedid3s[]=12; // ID3_V2_2 // $allowedid3s[]=28; // ID3_V2_3 // $allowedid3s[]=60; // ID3_V2_4 // $allowedid3s[]=31; // UNKNOWN! $index = 1; foreach($songs as $song){ $version = id3_get_version($song['path']); if($version & ID3_V1_0) $tag = id3_get_tag($song['path'], ID3_V1_0); if ($version & ID3_BEST) $tag = id3_get_tag($song['path'], ID3_BEST); if($tag) $this->songs[$index]['file'] = $song['file']; $this->songs[$index]['artist'] = $tag['artist']; $this->songs[$index]['title'] = $tag['title']; $this->songs[$index]['version'] = $version; $index++; }