Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.04 KB | None | 0 0
  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.  * @version   SVN: Release: $Id: simple.php 276201 2009-02-20 16:55:07Z kvz $
  14.  * @link      http://trac.plutonia.nl/projects/system_daemon
  15.  */
  16.  
  17. /**
  18.  * System_Daemon Example Code
  19.  *
  20.  * If you run this code successfully, a daemon will be spawned
  21.  * and stopped directly. You should find a log enty in
  22.  * /var/log/simple.log
  23.  *
  24.  */
  25.  
  26. // Make it possible to test in source directory
  27. // This is for PEAR developers only
  28. ini_set('include_path', ini_get('include_path').':..');
  29.  
  30. // Include Class
  31. error_reporting(E_ALL);
  32. require_once "System/Daemon.php";
  33.  
  34. // Bare minimum setup
  35. System_Daemon::setOption("appName", "simple");
  36. System_Daemon::setOption("authorEmail", "blizzz@owncloud.com");
  37. System_Daemon::setOption("logLocation", "/var/www/testlog.log");
  38. System_Daemon::setOption("appPidLocation", "/var/www/testpids/simple/testdaeon.pid");
  39. System_Daemon::setOption("appRunAsGID", "33");
  40. System_Daemon::setOption("appRunAsUID", "33");
  41.  
  42. System_Daemon::setOption("appDir", dirname(__FILE__));
  43. System_Daemon::log(System_Daemon::LOG_INFO, "Daemon not yet started so ".
  44.     "this will be written on-screen");
  45.  
  46. // Spawn Deamon!
  47. System_Daemon::start();
  48. System_Daemon::log(System_Daemon::LOG_INFO, "Daemon: '".
  49.     System_Daemon::getOption("appName").
  50.     "' spawned! This will be written to ".
  51.     System_Daemon::getOption("logLocation"));
  52.  
  53. // Your normal PHP code goes here. Only the code will run in the background
  54. // so you can close your terminal session, and the application will
  55. // still run.
  56.  
  57. while(true) {
  58.     System_Daemon::iterate(20);
  59.     System_Daemon::log(System_Daemon::LOG_INFO, "Daemon: '".
  60.     System_Daemon::getOption("appName").
  61.     "' still running ".
  62.     System_Daemon::getOption("logLocation"));
  63. }
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement