Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2007
    Posts
    31

    Exclamation Unanswered: Refresh read from a file.[Resolved]

    This is my script. I want to do somehow to read my file every 10 seconds for example and show me in the page. I try with a tag in html, it is working, but it is too visible. Enybody know how cold I do this?
    Thanks.



    <?php
    $fisierulmeu = "fisier.txt";
    $handle = fopen($fisierulmeu, 'r');
    $Data = fgets($handle, 512);
    fclose($handle);
    echo ' '.$Data.' ';
    ?>
    Last edited by flobeats; 05-30-07 at 07:27.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    might be better to do this as an AJAX procedure
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2007
    Posts
    31
    Thanks, other opinions..?

  4. #4
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Why would you be wanting to do this?
    You need to give us a better understanding of what you are trying to achieve before we can offer solutions.

    What is it for? Is it a chat interface?
    In your current code have you considered what happens when the data gets larger than 512 bytes?
    Do you know that reads on large files are expensive using fgets (especially if EVERYONE is trying to read them every 10 seconds).
    When do writes occur on this file? Are you locking the file while you do each?
    Is a 10 second refresh applicable or could it be longer?
    Last edited by aschk; 05-24-07 at 11:54.

  5. #5
    Join Date
    Apr 2007
    Posts
    31
    This is a script in a html page; the script read a number from a file.txt. I must do a demo page, a page that monitorize a temperature senzor. I put in the file.txt: 23 Celsius, 24 Celsius, 25 Celsius..etc. I must repeat the read from file, at 10-15 seconds. I don t need a data larger than 512 bytes.
    Thanks.

  6. #6
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    You could just write a page PHP as you have above :
    Code:
    <html>
    <head>
      <meta http-equiv="refresh" content="10">
    </head>
    
    <body>
    <?php
      $fisierulmeu = "fisier.txt";
      $handle = fopen($fisierulmeu, 'r');
      $Data = fgets($handle, 512);
      fclose($handle);
      echo ' '.$Data.' ';
    ?>
    </body>
    
    </html>
    And then put an iframe into the page you want to display it in
    <iframe src="mypage.php"></iframe>

    The iframe should refresh every 10 seconds...

  7. #7
    Join Date
    Apr 2007
    Posts
    31
    Thank you very much, it is just what i need.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •