Code Monkey home page Code Monkey logo

supervisor's Introduction

Supervisor

Latest Version Software License Build Status Code Coverage Quality Score Total Downloads

Gitter

PHP library for managing Supervisor through XML-RPC API.

Install

Via Composer

$ composer require supervisorphp/supervisor

Usage

use Supervisor\Supervisor;
use Supervisor\Connector\XmlRpc;
use fXmlRpc\Client;
use fXmlRpc\Transport\HttpAdapterTransport;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
use \Http\Message\MessageFactory\DiactorosMessageFactory as MessageFactory;

//Create GuzzleHttp client
$guzzleClient = new \GuzzleHttp\Client(['auth' => ['user', 'password']]);

// Pass the url and the guzzle client to the XmlRpc Client
$client = new Client(
    'http://127.0.0.1:9001/RPC2',
    new HttpAdapterTransport(
        new MessageFactory(),
        new GuzzleAdapter($guzzleClient))
);

// Pass the client to the connector
// See the full list of connectors bellow
$connector = new XmlRpc($client);

$supervisor = new Supervisor($connector);

// returns Process object
$process = $supervisor->getProcess('test_process');

// returns array of process info
$supervisor->getProcessInfo('test_process');

// same as $supervisor->stopProcess($process);
$supervisor->stopProcess('test_process');

// Don't wait for process start, return immediately
$supervisor->startProcess($process, false);

// returns true if running
// same as $process->checkState(Process::RUNNING);
$process->isRunning();

// returns process name
echo $process;

// returns process information
$process->getPayload();

Currently available connectors:

Note: fXmlRpc can be used with several HTTP Clients. See the list on it's website. This is the reason why Client specific connectors has been removed.

Authentication

As of version 3.0.0 setCredentials is no longer part of the Connector interface (meaning responsibility has been fully removed).You have to provide authentication data to the HTTP Client of your choice. (For example Guzzle supports it out-of-the-box) Also, Bridges implemented by fXmlRpc supports to set custom headers.

Exception handling

For each possible fault response there is an exception. These exceptions extend a common exception, so you are able to catch a specific fault or all. When an unknown fault is returned from the server, an instance if the common exception is thrown. The list of fault responses and the appropriate exception can be found in the class.

use Supervisor\Exception\Fault;
use Supervisor\Exception\Fault\BadName;

try {
	$supervisor->restart('process');
} catch (BadName $e) {
	// handle bad name error here
} catch (Fault $e) {
	// handle any other errors here
}

For developers: Fault exceptions are automatically generated, there is no need to manually modify them.

Configuration and Event listening

Configuration and Event components have been moved into their own repository.

Further info

You can find the XML-RPC documentation here: http://supervisord.org/api.html

Notice

If you use PHP XML-RPC extension to parse responses (which is marked as EXPERIMENTAL). This can cause issues when you are trying to read/tail log of a PROCESS. Make sure you clean your log messages. The only information I found about this is a comment.

You will also have to make sure that you always call the functions with correct parameters. Zend connector will trigger an error when incorrect parameters are passed. See this issue for details. (Probably this won't change in near future based on my inspections of the code.) Other connectors will throw a Fault exception.

Please note that Supervisor tests currently fail on PHP 7.0 and HHVM using Supervisor 3.0.

Testing

$ composer test

Functional tests (behat):

$ behat

Vagrant

There is a Vagrantfile provided in this repo which you can use to run functional tests without installing Supervisor on your local machine. It installs the latest version from PyPi, but the library itself is tested against 3.0, which is the lowest officially supported Supervisor version.

Contributing

Please see CONTRIBUTING for details.

Deprecated libraries

While this tries to a be a complete Supervisor client, this isn't the first one. However some authors decided to deprecate their packages in favor of this:

Credits

License

The MIT License (MIT). Please see License File for more information.

supervisor's People

Contributors

sagikazarmark avatar prolic avatar andreybolonin avatar gabrielpra1 avatar gl3n avatar raulp 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.