Skip to content

Commit

Permalink
Whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
kvz committed Nov 9, 2010
1 parent c77848c commit fc158eb
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions examples/logparser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?php
/**
* System_Daemon turns PHP-CLI scripts into daemons.
*
*
* PHP version 5
*
* @category System
Expand All @@ -15,23 +15,23 @@

/**
* System_Daemon Example Code
*
*
* If you run this code successfully, a daemon will be spawned
* but unless have already generated the init.d script, you have
* no real way of killing it yet.
*
* In this case wait 3 runs, which is the maximum for this example.
*
*
*
* In this case wait 3 runs, which is the maximum for this example.
*
*
* In panic situations, you can always kill you daemon by typing
*
*
* killall -9 logparser.php
* OR:
* killall -9 php
*
*
*/

// Allowed arguments & their defaults
// Allowed arguments & their defaults
$runmode = array(
'no-daemon' => false,
'help' => false,
Expand Down Expand Up @@ -81,13 +81,13 @@

// This program can also be run in the forground with runmode --no-daemon
if (!$runmode['no-daemon']) {
// Spawn Daemon
// Spawn Daemon
System_Daemon::start();
}

// With the runmode --write-initd, this program can automatically write a
// With the runmode --write-initd, this program can automatically write a
// system startup file called: 'init.d'
// This will make sure your daemon will be started on reboot
// This will make sure your daemon will be started on reboot
if (!$runmode['write-initd']) {
System_Daemon::info('not writing an init.d script this time');
} else {
Expand All @@ -114,27 +114,27 @@
// While checks on 3 things in this case:
// - That the Daemon Class hasn't reported it's dying
// - That your own code has been running Okay
// - That we're not executing more than 3 runs
// - That we're not executing more than 3 runs
while (!System_Daemon::isDying() && $runningOkay && $cnt <=3) {
// What mode are we in?
$mode = '"'.(System_Daemon::isInBackground() ? '' : 'non-' ).
'daemon" mode';

// Log something using the Daemon class's logging facility
// Depending on runmode it will either end up:
// - In the /var/log/logparser.log
// - On screen (in case we're not a daemon yet)
// - On screen (in case we're not a daemon yet)
System_Daemon::info('{appName} running in %s %s/3',
$mode,
$cnt
);

// In the actuall logparser program, You could replace 'true'
// With e.g. a parseLog('vsftpd') function, and have it return
// either true on success, or false on failure.
$runningOkay = true;
//$runningOkay = parseLog('vsftpd');

// Should your parseLog('vsftpd') return false, then
// the daemon is automatically shut down.
// An extra log entry would be nice, we're using level 3,
Expand All @@ -145,7 +145,7 @@
System_Daemon::err('parseLog() produced an error, '.
'so this will be my last run');
}

// Relax the system by sleeping for a little bit
// iterate also clears statcache
System_Daemon::iterate(2);
Expand All @@ -155,4 +155,4 @@

// Shut down the daemon nicely
// This is ignored if the class is actually running in the foreground
System_Daemon::stop();
System_Daemon::stop();

0 comments on commit fc158eb

Please sign in to comment.