Giter VIP home page Giter VIP logo

processmanager's Introduction

Process Control Tools

Requirements

  • posix and pcntl extensions
  • PHP5.4+ (Uses modern syntax)
  • Basic knowledge of PHP on the command line

Daemon

A really useful tool with a very boring name. Daemonize your PHP scripts with two lines of code.

Usage

Code:

<?php
// Preferred:
require 'vendor/autoload.php'; // composer
declare(ticks=1);
(new Firehed\ProcessControl\Daemon)
    ->setUser('sites')
    ->setPidFileLocation('/var/run/gearman-manager2.pid')
    ->setStdoutFileLocation(sys_get_temp_dir().'/my.log')
    ->setStdErrFileLocation('/dev/null')
    ->setProcessName(basename(__FILE__).' master process')
    ->autoRun();
// The rest of your original script

CLI:

php yourscript.php {status|start|stop|restart|reload|kill}

Yes, it's that simple.

Actions

  • Status: Check the status of the process. Returns:
    • 0 if running
    • 1 if dead but pidfile is hanging around
    • 3 if stopped
  • Start: Start the daemon
  • Stop: Stop the daemon gracefully via SIGTERM
  • Restart: Stop (if running) and start
  • Reload: Send SIGUSR1 to daemon (you need to implement a reload function, see below)
  • Kill: Kill the daemon via SIGKILL (kill -9)

Options

  • setProcessName($string): Set the process name as it will appear in utilities such as top. This is only supported under PHP5.5+.
  • setPidFileLocation($path): Specify the location of the pid file. This file stores the process id when the daemon is running, and goes away when the daemon stops.
  • setStdoutFileLocation($path): File where anything that would have been written to STDOUT (echo, print, etc) goes.
  • setStdErrFileLocation($path): File where anything that would have been written to STDERR goes. It appears that display_errors no longer writes to STDERR after daemonizing, so setting this to /dev/null is pretty safe.
  • setUser($system_user): If you want to have the process run as a lower-security user, specify the username here. This is especially helpful if you start the daemon on system with chkconfig and /etc/init.d, since those run as root.

To come later(?):

  • Verbose output
  • Synchronous mode (do not daemonize for debugging)
  • Log file configuration

Useful tips

  • STDOUT (echo, print) is redirected to the log file.
  • The "reload" command won't do anything without installing a handler for SIGUSR1. Examples are due shortly.

Known Issues

  • STDERR doesn't appear to go anywhere, despite opening a logfile for it.
  • The script can't set up "reload" bindings automatically. This is a PHP limitation: "The declare construct can also be used in the global scope, affecting all code following it (however if the file with declare was included then it does not affect the parent file)". http://docs.php.net/manual/en/control-structures.declare.php

processmanager's People

Contributors

firehed avatar skyzyx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

processmanager's Issues

example.php seems not correct

the Daemon class is prefect.
but the example.php sesms has a small problem .
at the top , there should have the code

declare(ticks = 1);

otherwise, you can not stop the daemon, becase the signal handler will never be executed

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.