Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. infinite loop while using php's dir object..?

infinite loop while using php's dir object..?

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
phplampcomtoolsquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cjoki
    wrote on last edited by
    #1

    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?

    C 1 Reply Last reply
    0
    • C cjoki

      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?

      C Offline
      C Offline
      chevu
      wrote on last edited by
      #2

      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.

      C 1 Reply Last reply
      0
      • C chevu

        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.

        C Offline
        C Offline
        cjoki
        wrote on last edited by
        #3

        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

        C 1 Reply Last reply
        0
        • C 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

          C Offline
          C Offline
          chevu
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups