read lines of file without parsing the lines

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default read lines of file without parsing the lines

    Hello!

    Currently i have a logfile which tracks a certain feature on my server.
    Every time the feature accurs my script appends a line in the file.

    Can i find out how many lines the log file currently contains without
    opening the complete file en count every line in a loop?

    I want to do this because reading the file every time can take a long time.
    the log file is emptied every week but on the end of the week the file
    contains more than 20.000 lines.

    Thanks in Afvance
    W. Paulisse


    W. Paulisse Guest

  2. Similar Questions and Discussions

    1. Add lines to pages in a file
      Ok, I've heard that I can do this with templates. But I'm not sure how to do this. Here is what I want to have. I have a PDF with several pages. Each...
    2. Vertical lines in AI graphics PDF as broken lines?
      I have an InDesign CS1 doc that has an Illustrator CS1 EPS file placed in it. The graphic is a barcode for a coupon. It is only many vertical lines,...
    3. Acrobat 6 changes solid lines to dashed lines
      Is Adobe planning to provide a fix for the problem where solid lines will display as dashed lines when viewed in Acrobat 6? If yes, when? Thank...
    4. Help parsing multiple lines?
      I have to cut and paste lots of contact info into a FMP database. I copy text from multiple sources and paste it into my database one line at a...
    5. Newbie - skipping lines of a file.
      tadmc@augustmail.com (Tad McClellan) writes: The irony is that I somehow failed to recognise this as a FAQ! I just answered the question...
  3. #2

    Default Re: read lines of file without parsing the lines

    I dont know any function doing this in fast way. But If you want something
    simple, check how I do it :

    $file = file("file.txt");
    $numLine = count($file);

    Savut

    "W. Paulisse" <ihate@spam.nl> wrote in message
    news:40295482$0$575$e4fe514c@news.xs4all.nl...
    > Hello!
    >
    > Currently i have a logfile which tracks a certain feature on my server.
    > Every time the feature accurs my script appends a line in the file.
    >
    > Can i find out how many lines the log file currently contains without
    > opening the complete file en count every line in a loop?
    >
    > I want to do this because reading the file every time can take a long
    time.
    > the log file is emptied every week but on the end of the week the file
    > contains more than 20.000 lines.
    >
    > Thanks in Afvance
    > W. Paulisse
    >
    >
    Savut Guest

  4. #3

    Default Re: read lines of file without parsing the lines

    Super simple way is to pad every line with spaces so each line is always the
    same length
    then lines = file size / (line lenght +1 )
    the +1 is for the new line chr \n or +2 on windows \r\n

    --
    Mike Bradley
    [url]http://www.gzentools.com[/url] -- free online php tools
    "W. Paulisse" <ihate@spam.nl> wrote in message
    news:40295482$0$575$e4fe514c@news.xs4all.nl...
    > Hello!
    >
    > Currently i have a logfile which tracks a certain feature on my server.
    > Every time the feature accurs my script appends a line in the file.
    >
    > Can i find out how many lines the log file currently contains without
    > opening the complete file en count every line in a loop?
    >
    > I want to do this because reading the file every time can take a long
    time.
    > the log file is emptied every week but on the end of the week the file
    > contains more than 20.000 lines.
    >
    > Thanks in Afvance
    > W. Paulisse
    >
    >

    CountScubula Guest

  5. #4

    Default Re: read lines of file without parsing the lines


    "W. Paulisse" <ihate@spam.nl> wrote in message
    news:40295482$0$575$e4fe514c@news.xs4all.nl...
    > Hello!
    > Can i find out how many lines the log file currently contains without
    > opening the complete file en count every line in a loop?
    If your server OS is a *nix variant, you might like to try this:

    $numlines = intval(`wc -l /path/to/logfile`);
    > W. Paulisse
    Cheers,
    thunder


    thunder Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139