infinite loop while using php's dir object..?
-
Hello All, My co-worker has a script that was caught in a infinite loop... during one run of the script. It has not repeated this behaviour since. After reading the docs online (w3schools http://www.w3schools.com/php/func_directory_dir.asp[^]) I see this returns a directory stream. I am wondering if you use the objects function "read()" as the condition of a while loop...
$dir = dir('/pathway/to/directory'); while($dir->read()!==false) { ... process files... }
...is it possible to cause an infinite loop when a new file is added via a different script to the same directory during this scripts execution? the scripts run on a lamp system with ample resources. Ideas? -
Hello All, My co-worker has a script that was caught in a infinite loop... during one run of the script. It has not repeated this behaviour since. After reading the docs online (w3schools http://www.w3schools.com/php/func_directory_dir.asp[^]) I see this returns a directory stream. I am wondering if you use the objects function "read()" as the condition of a while loop...
$dir = dir('/pathway/to/directory'); while($dir->read()!==false) { ... process files... }
...is it possible to cause an infinite loop when a new file is added via a different script to the same directory during this scripts execution? the scripts run on a lamp system with ample resources. Ideas?Well I am not sure but according to OS fundamentals these things should be possible, 1) Rename and delete of directory not allowed 2) Rename and delete (and editing) is not allowed for the file getting processed in current loop instance 3) One should be able to rename or delete or editing a file which is not getting processed in current loop instance 4) One should be able to add new file in that directory. These all are theoretically, one can omit or change these rules for his OS. And sorry I haven't tried the situation you gave. But I think it should be possible. And it might led to infinite loop.
-
Well I am not sure but according to OS fundamentals these things should be possible, 1) Rename and delete of directory not allowed 2) Rename and delete (and editing) is not allowed for the file getting processed in current loop instance 3) One should be able to rename or delete or editing a file which is not getting processed in current loop instance 4) One should be able to add new file in that directory. These all are theoretically, one can omit or change these rules for his OS. And sorry I haven't tried the situation you gave. But I think it should be possible. And it might led to infinite loop.
chevu, Thank you for your response. To be clearer I should state the process files was really just reading file names...I'm not sure that it matters. The script is still behaving normally, so I can only think that it was a fluke or maybe a sign of system instability (power suppply maybe). All the best! cjoki
-
chevu, Thank you for your response. To be clearer I should state the process files was really just reading file names...I'm not sure that it matters. The script is still behaving normally, so I can only think that it was a fluke or maybe a sign of system instability (power suppply maybe). All the best! cjoki
cjoki, As per the mutual exclusion fundamental no mater what you are doing (read/write) with data (in this case reading file name) you cannot change that name. Ya but you might have seen in windows or unix or linux that in if you have opened one folder at two differ location and you add one file/folder at one place changes get reflected to another place. I am not so sure about windows directroy structure in detail. But for unix I know that once you add new file in directory its inode will be added to director file structure list and those changes can be read using directory structure. I dont know whether I am able to clarify your doubt or not. It will be better if you find out such script is working on your system and if it is not working then try to run such script and check. In both case please let me know the result I would like to know whether it is possible or not. Thanks.