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
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
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
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
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
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
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
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.