Files
varlog/_cache/articles/81b17b21-4099-437c-9611-b4fbd4b3416e.json
T
2026-05-15 10:37:48 +02:00

1 line
1.2 KiB
JSON

{"uuid":"81b17b21-4099-437c-9611-b4fbd4b3416e","slug":"simuler-tail-en-php","title":"Simuler tail en PHP","author":"cedric@abonnel.fr","published":true,"published_at":"2023-02-02 07:45:44","created_at":"2023-02-02 07:45:44","updated_at":"2023-02-02 07:45:44","revisions":[],"cover":"","files_meta":[],"external_links":[],"seo_title":"","seo_description":"","og_image":"","category":"Informatique","content":"# Simuler tail en PHP\n\n![Simuler tail en PHP](dummy.png)\n\n```PHP\n<?php\n$handle = popen(\"tail -f /etc/httpd/logs/access.log 2>&1\", 'r');\nwhile(!feof($handle)) {\n $buffer = fgets($handle);\n echo \"$buffer<br/>\\n\";\n ob_flush();\n flush();\n}\npclose($handle);\n```\n\n```PHP\nfunction follow($file)\n{\n $size = 0;\n while (true) {\n clearstatcache();\n $currentSize = filesize($file);\n if ($size == $currentSize) {\n usleep(100);\n continue;\n }\n\n $fh = fopen($file, \"r\");\n fseek($fh, $size);\n\n while ($d = fgets($fh)) {\n echo $d;\n }\n\n fclose($fh);\n $size = $currentSize;\n }\n}\n\nfollow(\"file.txt\");\n```","featured":false,"tags":[]}