jaymc Posted May 1, 2008 Share Posted May 1, 2008 I have a script that reads the MP3 tags of an Mp3 file, its quite intensive but ok when doing just one songs I have created a scrtipt which will read all files (mp3s) in a DIR and pass the file into the PHP IDE tag reader The script falls over when it hits max allowed memory as defined in php.ini Not sure why as its currently set at 300M, but never the less it hits it. Question is, how can I somehow clear the memory used by the script in each loop So, rather than the scripts memory needs (for each song) being stored until the script has finished, I want to clear it when its not needed Any ideas Quote Link to comment Share on other sites More sharing options...
micah1701 Posted May 1, 2008 Share Posted May 1, 2008 someone will hopefully answer with something better, and more direct to what you're trying to do.. but I was thinking, you could perhaps make 2 scripts. the first one is your script with the loop that looks up all the files in the directory and loops through them. Then each time through the loop it triggers the second script,perhaps using exec(). This way you'd be forking the process - one for each time through the loop - and you don't have to worry about that second script timing out. then, as the second script finishes doing its business - it can save its findings either to a database table or a common flat file. Quote Link to comment Share on other sites More sharing options...
jaymc Posted May 1, 2008 Author Share Posted May 1, 2008 Ok, so your saying for each song, run my IDE TAG READER as a seperate script altogether, using the likes of exec for example exec("php -f ide_tag_reader.php"); Thus the memory use for each loop will actually only be per song, and not the accumulation of all songs Please correct me if I have miss understood your approach If not, how can I pass a songname via this exec("php -f ide_tag_reader.php"); as exec("php -f ide_tag_reader.php?songname=beans.mp3"); will not work Dirty approach any how, but if no one else has a solution.. P.S - I think its known as clearing the MEMORY BUFFER Quote Link to comment Share on other sites More sharing options...
rhodesa Posted May 1, 2008 Share Posted May 1, 2008 Read more about it here: http://us3.php.net/features.commandline I would use passthru, so that the output from the child script goes right to the display of the parent. To pass the name it would be like: <?php $script = 'ide_tag_reader.php'; foreach($files as $file){ passthru('php -f '.escapeshellarg($script).' '.escapeshellarg($file)); } ?> <?php $file = $argv[1]; //do stuff here ?> Quote Link to comment Share on other sites More sharing options...
jaymc Posted May 1, 2008 Author Share Posted May 1, 2008 Ok using t Read more about it here: http://us3.php.net/features.commandline I would use passthru, so that the output from the child script goes right to the display of the parent. To pass the name it would be like: <?php $script = 'ide_tag_reader.php'; foreach($files as $file){ passthru('php -f '.escapeshellarg($script).' '.escapeshellarg($file)); } ?> <?php $file = $argv[1]; //do stuff here ?> Ok using that method inside 'ide_tag_reader.php' I can get the names via $_GET? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted May 1, 2008 Share Posted May 1, 2008 $_GET/$_POST are only for PHP via the web. Command line PHP uses $argv. If there are more variables the child script needs from the parent, just pass them as arguments Quote Link to comment Share on other sites More sharing options...
jaymc Posted May 1, 2008 Author Share Posted May 1, 2008 Oh sorry I completed missed the relivence of $argv[1]; example Ok, so lets say I passed 3 names to the script, is this correct passthru('php -f '.escapeshellarg($script).' '.escapeshellarg($file1).'&'.escapeshellarg($file2).'&'.escapeshellarg($file3)); $file1 = $argv[1]; $file2 = $argv[2]; $file3 = $argv[3]; Quote Link to comment Share on other sites More sharing options...
rhodesa Posted May 1, 2008 Share Posted May 1, 2008 nope...they are command line arguments, so spaces, not &s passthru('php -f '.escapeshellarg($script).' '.escapeshellarg($file1).' '.escapeshellarg($file2).' '.escapeshellarg($file3)); and then make your script dynamic, so you can have as many files as you want (even though the point is to limit the number <?php for($n = 1;$n < count($argv);$n++){ $file = $argv[$n]; } ?> Quote Link to comment Share on other sites More sharing options...
jaymc Posted May 1, 2008 Author Share Posted May 1, 2008 Ok cool, although for the moment I will put this on the back burner before testing and implementation Is there a special function in PHP to clear the memory buffer for redundant variables stored in memory that are no longer needed Kind of like a flush Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.