Git Product home page Git Product logo

daemon-php's Introduction

DaemonPHP Class

Introduction

This class allows you to easily create UNIX-daemons.

Start-up and use

All you need to do - is to override the abstract method run()

For example:

<?php
require_once 'daemon.php';

class MyDaemon extends DaemonPHP {

    public function run() {
        while (true) {
        }
    }
}

$daemon = new MyDaemon('/tmp/test.pid');

$daemon->setChroot('/home/shaman/work/PHPTest/daemon')
    ->setLog('/my.log')
    ->setErr('/my.err')
    ->handle($argv);
}
?>

As an example of a file run.php

  • To start:

    localhost:~$ php run.php start

  • To stop:

    localhost:~$ php run.php stop

  • To check the status:

    localhost:~$ php run.php status

  • To restart:

    localhost:~$ php run.php restart

Constructor of the class DaemonPHP

In the constructor you can pass the absolute path to the PID-file daemon.

If no path is passed to the constructor, the default PID-file will be in the same directory under the name daemon-php.pid

Method setChroot()

This method performs chroot to the specified directory.

To do this requires the right of user root.

After completing chrut root directory will be referred to the directory.

For example:

<?php
//Some code

$daemon->setChroot('/home/shaman/work/PHPTest/daemon') //Directory for chroot
    ->setLog('/my.log')
    ->setErr('/my.err'); //After chroot files can created in /home/shaman/work/PHPTest/daemon

//Some code
?>

Method setLog()

This method sets the absolute path for the log file.

By default, the file will be created in the current directory under the name daemon-php.log

Method setErr()

This method sets the absolute path for the error log file.

By default, the file will be created in the current directory under the name daemon-php.err

Method handle($argv)

This method handles the command line arguments - $argv.

File php_error.php

This file only appears if there are errors in the PHP.

daemon-php's People

Contributors

shamanis avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.