Jump to content

Search the Community

Showing results for tags 'php read log'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Hi I'm trying to watch a plain text file for any changes. I want to use PHP and read the file line by line as new lines are added. Some times 1 line may be added, other times dozens of lines could be added. I want to read each line and check if it matches any keywords.. This is what I've got so far, but it's not line by line... it's buffer size based. <?php $file='log.txt'; $line = $lastpos = 0; while (true) { usleep(500000); clearstatcache(false, $file); $len = filesize($file); if ($len < $lastpos) { $lastpos = $len; } elseif ($len > $lastpos) { $f = fopen($file, "rb"); if ($f === false) die(); fseek($f, $lastpos); while (!feof($f)) { $buffer = fread($f, 4096); if ($lastpos > 0) { if (strpos($buffer, 'MATCH') !== false) echo "$line\r\n"; } flush(); $line++; } $lastpos = ftell($f); fclose($f); } } ?> Can anyone help point me in the right direction. Ideally I don't want to keep the log in memory as it could grow to a reasonable size. Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.