| 1 |
lars |
1 |
#!/usr/bin/php -q
|
|
|
2 |
<?php
|
|
|
3 |
/**
|
|
|
4 |
* System_Daemon turns PHP-CLI scripts into daemons.
|
|
|
5 |
*
|
|
|
6 |
* PHP version 5
|
|
|
7 |
*
|
|
|
8 |
* @category System
|
|
|
9 |
* @package System_Daemon
|
|
|
10 |
* @author Kevin <kevin@vanzonneveld.net>
|
|
|
11 |
* @copyright 2008 Kevin van Zonneveld
|
|
|
12 |
* @license http://www.opensource.org/licenses/bsd-license.php New BSD Licence
|
|
|
13 |
* @link http://github.com/kvz/system_daemon
|
|
|
14 |
*/
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* System_Daemon Example Code
|
|
|
18 |
*
|
|
|
19 |
* If you run this code successfully, a daemon will be spawned
|
|
|
20 |
* and stopped directly. You should find a log enty in
|
|
|
21 |
* /var/log/pearlog.log
|
|
|
22 |
*
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
// Make it possible to test in source directory
|
|
|
26 |
// This is for PEAR developers only
|
|
|
27 |
ini_set('include_path', ini_get('include_path').':..');
|
|
|
28 |
|
|
|
29 |
// Include Class
|
|
|
30 |
error_reporting(E_ALL);
|
|
|
31 |
require_once "System/Daemon.php";
|
|
|
32 |
|
|
|
33 |
// Initialize PEAR_Log instance
|
|
|
34 |
$my_log_instance = &Log::factory('file', '/tmp/pearlog.log', 'pearlog');
|
|
|
35 |
|
|
|
36 |
// Bare minimum setup
|
|
|
37 |
System_Daemon::setOption("appName", "pearlog");
|
|
|
38 |
System_Daemon::setOption("appDir", dirname(__FILE__));
|
|
|
39 |
System_Daemon::setOption("usePEARLogInstance", $my_log_instance);
|
|
|
40 |
System_Daemon::log(System_Daemon::LOG_INFO, "Daemon not yet started. ".
|
|
|
41 |
"Every logline will end up in whatever usePEARLogInstance->log() says");
|
|
|
42 |
|
|
|
43 |
// Spawn Deamon!
|
|
|
44 |
System_Daemon::start();
|
|
|
45 |
System_Daemon::log(System_Daemon::LOG_INFO, "Daemon started. ".
|
|
|
46 |
"Every logline will end up in whatever usePEARLogInstance->log() says");
|
|
|
47 |
|
|
|
48 |
// Your normal PHP code goes here. Only the code will run in the background
|
|
|
49 |
// so you can close your terminal session, and the application will
|
|
|
50 |
// still run.
|
|
|
51 |
|
|
|
52 |
System_Daemon::stop();
|