PHP recursive function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ciri
    New Member
    • Oct 2007
    • 18

    #1

    PHP recursive function

    Hi all, I need a PHP script that checks the creation date of a file each 5 seconds, if creation date is changed it reload the page via javascript
    I' ve tried with:

    function verificaData($d ataCreazione)
    {
    flush();
    sleep(5);
    flush();
    $datacreTemp= filectime('SiSe Fi/SiSeFi.png');
    if ($dataCreazione ==$datacreTemp)
    {
    verificaData($d atacreTemp);
    }
    else
    {
    echo'<script>wi ndow.location.r eload();</script>' ;
    }
    }
    I just call the function after the <body> tag.
    Why it doesn't work?
    What wrong with this?

    Thanks.
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    Hi,

    I fail to see why this funtion has to be recursive, if the page that's calling this function is to be open constantly you could probably just to with a loop of some sort.

    I don't know the context or the use of you php file, but perhaps you could look at the filemtime function.

    Hope this helps..

    Comment

    • Ciri
      New Member
      • Oct 2007
      • 18

      #3
      Originally posted by MarkoKlacar
      Hi,

      I fail to see why this funtion has to be recursive, if the page that's calling this function is to be open constantly you could probably just to with a loop of some sort.

      I don't know the context or the use of you php file, but perhaps you could look at the filemtime function.

      Hope this helps..

      Ok, thanks. I've tried your way:
      <?
      $creationTime=f ilemtime('myPic ture.png')
      while(true)
      {
      flush();
      sleep(5);
      if ($creationTime! =filemtime('myP icture.png')
      {
      echo'<script language=javasc ript> window.location .reload();</script>';
      }

      }
      ?>

      It seems to work only for one user per time.
      If I open only one instance of the browser it's perfect but if I open a second window on the same page both apps stops working and freeze the browser!
      Any suggestion?

      Thanks.

      Comment

      • MarkoKlacar
        Recognized Expert Contributor
        • Aug 2007
        • 296

        #4
        Hi,

        What happens if you remove flush()?

        Comment

        • Ciri
          New Member
          • Oct 2007
          • 18

          #5
          I've tried removing the flush(): the page never loads.
          This is the complete code of the page:

          <html>
          <head>
          </head>
          <body>
          <img src="SiSeFi/SiSeFi.png" style="backgrou nd-image:url(SiSeF i/SiSeFi_bckgrd.j peg)" alt=""/>

          <?
          $dataCreazione= filectime('SiSe Fi/SiSeFi.png');
          while ($dataCreazione ==filectime('Si SeFi/SiSeFi.png'))
          {
          sleep(5);
          }

          ?>

          </body>
          </html>

          Could you help me please understaing why it doesn't work?

          Thank you all guys.

          Comment

          • MarkoKlacar
            Recognized Expert Contributor
            • Aug 2007
            • 296

            #6
            Hi,

            Don't know if this solves you problem but you while statement looks different now(the names are wrong i know..)
            [PHP]if ($creationTime= =filemtime('myP icture.png')[/PHP]
            you use to have
            [PHP]if ($creationTime! =filemtime('myP icture.png')[/PHP]

            perhaps you need to look at that...

            Get back to us if you need more help, maybe I can provide you with an alternative solution if it'a an option for you...

            Good Luck..

            Comment

            Working...