Jump to content

[SOLVED] Clear memory


jaymc

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/103741-solved-clear-memory/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/103741-solved-clear-memory/#findComment-531160
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/103741-solved-clear-memory/#findComment-531161
Share on other sites

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
?>

Link to comment
https://forums.phpfreaks.com/topic/103741-solved-clear-memory/#findComment-531165
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/103741-solved-clear-memory/#findComment-531168
Share on other sites

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];

Link to comment
https://forums.phpfreaks.com/topic/103741-solved-clear-memory/#findComment-531178
Share on other sites

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];


  }
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/103741-solved-clear-memory/#findComment-531183
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.