Professional Web Applications Themes

read lines of file without parsing the lines - PHP Development

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...

  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. #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" <ihatespam.nl> wrote in message
    news:40295482$0$575$e4fe514cnews.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

  3. #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" <ihatespam.nl> wrote in message
    news:40295482$0$575$e4fe514cnews.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

  4. #4

    Default Re: read lines of file without parsing the lines


    "W. Paulisse" <ihatespam.nl> wrote in message
    news:40295482$0$575$e4fe514cnews.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

Similar Threads

  1. Add lines to pages in a file
    By Carlos_Cavazos@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 2
    Last Post: December 13th, 07:27 PM
  2. Vertical lines in AI graphics PDF as broken lines?
    By SuperMacGuy@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 2
    Last Post: September 11th, 08:30 PM
  3. Acrobat 6 changes solid lines to dashed lines
    By Connie_Nathanson@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 0
    Last Post: April 22nd, 02:52 PM
  4. Help parsing multiple lines?
    By in forum FileMaker
    Replies: 0
    Last Post: August 25th, 08:39 PM
  5. Newbie - skipping lines of a file.
    By Brian McCauley in forum PERL Miscellaneous
    Replies: 1
    Last Post: July 22nd, 12:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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