PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
jp_loh
Forum Newbie
Posts: 3 Joined: Thu Jun 01, 2006 7:47 am
Location: Philippines
Contact:
Post
by jp_loh » Thu Jun 01, 2006 7:55 am
Is there a way for me to monitor a file realtime in PHP from the CLI? I'm trying to copy a PERL script to PHP since I can't do PERL.
I want to upload data from a log file to the database as soon as an entry pops out.
I'm starting from this command:
Code: Select all
tail -n 0 -f <file> | php <script>
I'm not sure if this will put the entries in stdin or somewhere else like an argument.
Thanks!
ok
Forum Contributor
Posts: 393 Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land
Post
by ok » Thu Jun 01, 2006 9:05 am
I don't get it... why you use CLI???
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Jun 01, 2006 9:11 am
ok wrote: I don't get it... why you use CLI???
Why not? What's wrong with using CLI?
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Jun 01, 2006 9:14 am
jp_loh , you could try something like this:
Code: Select all
set_time_limit(0);
$fp = fopen('php://stdin', 'r');
while($line = fgets($fp)) {
// do something to $line
}
fclose($fp);
jp_loh
Forum Newbie
Posts: 3 Joined: Thu Jun 01, 2006 7:47 am
Location: Philippines
Contact:
Post
by jp_loh » Thu Jun 01, 2006 10:13 am
Weirdan wrote: jp_loh , you could try something like this:
Code: Select all
set_time_limit(0);
$fp = fopen('php://stdin', 'r');
while($line = fgets($fp)) {
// do something to $line
}
fclose($fp);
Hey thanks! I'll try that.
jp_loh
Forum Newbie
Posts: 3 Joined: Thu Jun 01, 2006 7:47 am
Location: Philippines
Contact:
Post
by jp_loh » Tue Jul 04, 2006 1:23 am
Okay, I'm back. I just realized that if I put a call to tail in rc.local, it waits for tail to end.
The problem is that I have three lines that will call tail in rc.local. So what happens is the first call is only executed. Is there another way to monitor a log file realtime (still using CLI)?