PHP library for managing supervisor through XML-RPC API.
Via Composer
composer require supervisorphp/supervisor
This library depends on the fast and powerful fXmlRpc library, which supports a number of adapters to use your preferred HTTP client to make connections.
In the example below, we will use the popular Guzzle HTTP client library.
This example requires some additional libraries to function. To include the necessary extra components, you can run:
composer require guzzlehttp/guzzle:^7.0
This example shows how to pass authentication credentials to Guzzle, initiate the fXmlRpc client, and pass that to supervisorPHP.
// Create Guzzle HTTP client
$guzzleClient = new GuzzleHttpClient([
'auth' => ['user', '123'],
]);
// Pass the url and the guzzle client to the fXmlRpc Client
$client = new fXmlRpcClient(
'http://127.0.0.1:9001/RPC2',
new fXmlRpcTransportPsrTransport(
new GuzzleHttpPsr7HttpFactory(),
$guzzleClient
)
);
// Or, if connecting via a Unix Domain Socket
$guzzleClient = new GuzzleHttpClient([
'curl' => [
CURLOPT_UNIX_SOCKET_PATH => '/var/run/supervisor.sock',
],
]);
$client = new fXmlRpcClient(
'http://localhost/RPC2',
new fXmlRpcTransportPsrTransport(
new GuzzleHttpPsr7HttpFactory(),
$guzzleClient
)
);
// Pass the client to the supervisor library.
$supervisor = new supervisorsupervisor($client);
// 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();
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.
/** @var supervisorsupervisor $supervisor */
try {
$supervisor->startProcess('process', true);
} catch (supervisorExceptionFaultBadNameException $e) {
// handle bad name error here
} catch (supervisorExceptionsupervisorException $e) {
// handle any other errors here
}
Configuration and Event components have been moved into their own repository.
You can find the supervisor XML-RPC documentation here: http://supervisord.org/api.html
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.
Please see CONTRIBUTING for details.
$ composer test
Functional tests (behat):
$ behat
This repository ships with a Docker Compose configuration and a Dockerfile for easy testing. Tests can be run via:
docker-compose run --rm ci
While this tries to be a complete supervisor client, this isn't the first one. However some authors decided to deprecate their packages in favor of this:
The MIT License (MIT). Please see License File for more information.