2
Back and forth, unable to collect data to understand what might be behind this, I get the following error:
Recursivedirectoryiterator::__Construct(path/to/directory) [recursivedirectoryiterator. -Construct]: failed to open dir: Too Many open files
The server where this error arises is running Apache/2.2.24 and PHP/5.3.22.
$workingPath = "caminho/para/directoria";
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($workingPath),
RecursiveIteratorIterator::SELF_FIRST
);
$files = iterator_to_array($iterator, true); /* tentativa de abafar o erro
como sugerido num tópico do SOEN
mas sem sucesso em resolver a questão */
foreach ($files as $file) {
// código a executar por cada ficheiro localizado
}
Question
How can I correctly assess the cause of this error and/or find out if there are limits I do not know that may be causing the same?
@Bacco I am not indicating anything in that sense... I actually assumed that after each step of the cycle the iterator itself would close the previous file!
– Zuul
@Bacco This example is the same code I use in the question, but I am passing a parameter to the iterator. My conversion from iterator to matrix is a step I just applied to see if it solved the question. Regarding
foreach()
vswhile()
, I don’t think that’s the problem, but I’ll try...– Zuul
Also try the flag "Filesystemiterator::SKIP_DOTS" in Directoryiterator so it doesn’t enter "recursion recursion":
RecursiveDirectoryIterator($workingPath,FilesystemIterator::SKIP_DOTS)
(I don’t know if it helps, I’ve never used these iterators)– Bacco
@Bacco I read this topic, but in the place where the iterator is running, it’s a temporary location that has up to 6 files at most :/ So... I don’t know...
– Zuul
But what about the tree? You’re using Recursivedirectoryiterator, not Directoryiterator, so it’s going in the subfolders.
– Bacco
I left the translation of the answer downstairs, in case it’s useful to someone else. If this is another case, I delete, and/or you can put a correct answer as soon as I find out. If I think of anything else, I’ll let you know. I’ll delete the comments from above, then delete this one.
– Bacco
If you can, test with Directoryiterator instead of Recursivedirectoryiterator just to see if the error changes.
– Bacco
@Bacco The operation is to go to the main folder and its sub-folders, locating a particular file and thumbnails! At most it is 5 directories so it gives a total of 6 files. But I am running tests...
– Zuul