file system and file get contents

Discussion in 'PHP' started by spaceman12, Mar 19, 2011.

  1. #1
    hello, i'm just not too sure of what i understand may be true or not. Suppose that i open a txt file on the server and write to it using fwrite and this has to continue at any given rate of time though not always. Is there any chances of returning me a half written text (file_get_contents) in case a long polling session is imposed to it(like every second)? Or only after finished procesing the writings,will it return me any data? Thanks
     
    spaceman12, Mar 19, 2011 IP
  2. ssmm987

    ssmm987 Member

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    3
    Trophy Points:
    43
    #2
    I know that when a file is readen and written a lot at the same time, errors can occur. Therefor it's better to use databases in such cases.
     
    ssmm987, Mar 20, 2011 IP
  3. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #3
    what I can guess is you are trying to create sort of very very basic chat system or a shoutbox, that will consume a lot of resources, but as far your question, here goes the answer.

    
    $fsize = filesize('yourfile.txt');
    $half = file_get_contents('yourfile.txt', 0, NULL, ceil($fsize/2) ); //reading second half, eq unix `tail` command
    
    Code (markup):
    I hope it helps your learning.
     
    Vooler, Mar 20, 2011 IP