Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > PHP
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 02-27-2008, 10:13 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
least expensive way to monitor a log file?

i'm writing a php script which will be running with max_execution time set to 0. the sole purpose of this script is to monitor a log file and print something once the log file has been modified.

this is obviously not going to be a public app, it's only meant to be used by a single web client at a time.

so, my question is, what's the least expensive way to monitor if a log file has changed.

right now, i'm just getting the filesize and clearing the statcache in every iteration of the loop which is once per second.

any other ideas or comments on that?
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 02-27-2008, 02:04 PM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 632
DJMaze is on a distinguished road
don't use PHP
Systems like Windows and GNU/Linux have somesort of "listener".
In that respect nothing happens until the system gets a notification of file changes. Then the sytem will send a message to your application that "something" has changed.

As an example (that i know of): SHChangeNotifyRegister Function ()
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 02-27-2008, 03:19 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
this is an ajax front end to system information. updating the UI through ajax is expensive, so i only want to do it when something has changed in a log file.

the system will not be able to notify the web client directly, so i will need js->php to get server-side info.

if i had a listener app writing to mysql, then php polling for changes, it would be more expensive than php just looking directly at the file.

so i guess the question was more like this: within PHP, what uses less resources, checking the file size, change time, or something else that would allow me to detect a change.
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 02-27-2008, 03:48 PM   #4 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
I do mtime then filesize - no sense in reading in a file if all that happened was that it was touched.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 02-27-2008, 04:43 PM   #5 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 595
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
It looks like someone may have exposed a php interface to linux's inotify filesystem monitor The RoLLing cOde: Get Spread Toolkit and inotify-tools PHPized
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 02-28-2008, 03:09 AM   #6 (permalink)
ShadyCraig
Recruit
 
Join Date: Sep 2005
Location: Loughborough, England, UK
Posts: 12
ShadyCraig is on a distinguished road
Lightbulb

There is a library available called FAM:

PHP: fam - Manual

fam_cancel_monitor -- Terminate monitoring
fam_close -- Close FAM connection
fam_monitor_collection -- Monitor a collection of files in a directory for changes
fam_monitor_directory -- Monitor a directory for changes
fam_monitor_file -- Monitor a regular file for changes
fam_next_event -- Get next pending FAM event
fam_open -- Open connection to FAM daemon
fam_pending -- Check for pending FAM events
fam_resume_monitor -- Resume suspended monitoring
fam_suspend_monitor -- Temporarily suspend monitoring
__________________
ShadyCraig is offline   Reply With Quote
Old 02-28-2008, 09:13 AM   #7 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 632
DJMaze is on a distinguished road
Right, that was it! I totally forgot about FAM

But, it wonder how useful it is for an AJAX driven page which is asking PHP requests all the time already. Afterall, it doesn't understand PUSH methods yet.
Maybe you can solve that using Comet
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 02-29-2008, 02:12 PM   #8 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
that's for the suggestions tek and shady.. haven't got around to trying them yet but it certainly is looking good.

djm, currently i'm setting max_execution_time to 0 and executing an ajax call. php keeps the request open and once it determines there's a change, it sends a response.

javascript then handles the response and opens another request.
__________________
testing 1 2 3
sde is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Log4j created file not able to delete while testing my application?? j.gohel Java 12 04-07-2006 10:52 AM
Create a Log File transfield PHP 12 03-15-2006 12:44 AM
.htaccess -- Image Hotlinking Prevention DavH27 HTML / CSS 0 08-27-2004 03:43 AM
.htaccess -- Custom Error Pages v1.1 DavH27 HTML / CSS 0 08-26-2004 04:40 PM
Dynamic File Includes Sarlok ASP Classic 0 02-24-2003 12:49 PM


All times are GMT -8. The time now is 02:48 AM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle