PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/README.md

http://github.com/shamanis/daemon-php
Markdown | 97 lines | 64 code | 33 blank | 0 comment | 0 complexity | 8959893441e4b182bd1ddae20c91ec7c MD5 | raw file
  1. DaemonPHP Class
  2. ===============
  3. Introduction
  4. ------------
  5. This class allows you to easily create UNIX-daemons.
  6. Start-up and use
  7. ----------------
  8. All you need to do - is to override the abstract method run()
  9. For example:
  10. <?php
  11. require_once 'daemon.php';
  12. class MyDaemon extends DaemonPHP {
  13. public function run() {
  14. while (true) {
  15. }
  16. }
  17. }
  18. $daemon = new MyDaemon('/tmp/test.pid');
  19. $daemon->setChroot('/home/shaman/work/PHPTest/daemon')
  20. ->setLog('/my.log')
  21. ->setErr('/my.err')
  22. ->handle($argv);
  23. }
  24. ?>
  25. As an example of a file run.php
  26. * To start:
  27. `localhost:~$ php run.php start`
  28. * To stop:
  29. `localhost:~$ php run.php stop`
  30. * To check the status:
  31. `localhost:~$ php run.php status`
  32. * To restart:
  33. `localhost:~$ php run.php restart`
  34. Constructor of the class DaemonPHP
  35. ----------------------------------
  36. In the constructor you can pass the absolute path to the PID-file daemon.
  37. If no path is passed to the constructor, the default PID-file will be in the same directory under the name `daemon-php.pid`
  38. Method setChroot()
  39. ------------------
  40. This method performs chroot to the specified directory.
  41. To do this requires the right of user root.
  42. After completing chrut root directory will be referred to the directory.
  43. For example:
  44. <?php
  45. //Some code
  46. $daemon->setChroot('/home/shaman/work/PHPTest/daemon') //Directory for chroot
  47. ->setLog('/my.log')
  48. ->setErr('/my.err'); //After chroot files can created in /home/shaman/work/PHPTest/daemon
  49. //Some code
  50. ?>
  51. Method setLog()
  52. ---------------
  53. This method sets the absolute path for the log file.
  54. By default, the file will be created in the current directory under the name `daemon-php.log`
  55. Method setErr()
  56. ---------------
  57. This method sets the absolute path for the error log file.
  58. By default, the file will be created in the current directory under the name `daemon-php.err`
  59. Method handle($argv)
  60. ---------------
  61. This method handles the command line arguments - `$argv`.
  62. File php_error.php
  63. ------------------
  64. This file only appears if there are errors in the PHP.