Search
 
SCRIPT & CODE EXAMPLE
 

PHP

detect change in log file in real time php

// read.php
<?php

// Last read position
$last = 0;

// Path to the updating log file
$file = 'log.txt';

while (true) {
    // PHP caches file information in order to provide faster
    // performance; In order to read the new filesize, we need
    // to flush this cache.
    clearstatcache(false, $file);

    // Get the current size of file
    $current = filesize($file);

    // Reseted the file?
    if ($current < $last) {
        $last = $current;
    }
    // If there's new content in the file
    elseif ($current > $last) {
        // Open the file in read mode
        $fp = fopen($file, 'r');

        // Set the file position indicator to the last position
        fseek($fp, $last);

        // While not reached the end of the file
        while (! feof($fp)) {
            // Read a line and print
            print fgets($fp);
        }

        // Store the current position of the file for the next pass
        $last = ftell($fp);

        // Close the file pointer
        fclose($fp);
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: codeigniter remote queries very slow 
Php :: get product by author id 
Php :: laravel return response with headers 
Php :: list.blade.php 
Php :: php cut after first sentence 
Php :: how to insert last id from crud grocery codeigniter 
Php :: mkdir recursive php 
Php :: Multiple trait declaration in PHP 
Php :: schema key issue laravel 
Php :: import csv to laravel 
Php :: Remove auto generate p from category description 
Php :: gan_sql 
Php :: avoid data insertion if an error occurs in laravel 
Php :: carbon 
Php :: php get long word in array 
Php :: php Get location date format 
Php :: FT_USER 
Php :: Route::whereIn 
Php :: php browser detection script 
Php :: css en linea php 
Php :: Comment ajouter un fil d’Ariane personnalisé à l’URL d’accueil dans WooCommerce 
Php :: code to set error for du[licate entry in php 
Php :: how to get data from two tables in laravel 
Php :: curl_setopt timeout php 
Php :: Fibers - PHP 8.1 
Php :: in php einen div 
Php :: atom emmet php 
Php :: laravel connection timed out 
Php :: simple_html_dom stream does not support seeking 
Php :: eager loading set limit to relationship 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =