vaites / php-apache-tika

Apache Tika bindings for PHP: extract text and metadata from documents, images and other formats
MIT License
116 stars 22 forks source link

Reduce memory usage with fclose() #14

Closed categoryshell closed 5 years ago

categoryshell commented 5 years ago

When indexing multiple files, for example within a for loop, there is excessive memory usage which could cause PHP to run into memory issues.

By adding fclose() on the file resource, after performing the cURL request, memory usage can be decreased a lot.

On 10 iterations with the file samples/sample5.pdf Without fclose():

Iteration 0
960M
Iteration 1
960M
Iteration 2
960M
Iteration 3
960M
Iteration 4
960M
Iteration 5
960M
Iteration 6
960M
Iteration 7
960M
Iteration 8
960M
Iteration 9
960M
Iteration 10
960M

And after adding fclose():


Iteration 0
192M
Iteration 1
192M
Iteration 2
192M
Iteration 3
192M
Iteration 4
192M
Iteration 5
192M
Iteration 6
192M
Iteration 7
192M
Iteration 8
192M
Iteration 9
192M
Iteration 10
192M```
vaites commented 5 years ago

You're right @JBleijenberg, a fclose() must be added. Will make some tests and merge for the next release.