PHP code example of supervisorphp / supervisor

1. Go to this page and download the library: Download supervisorphp/supervisor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

supervisorphp / supervisor example snippets


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

// Pass the url and the guzzle client to the fXmlRpc Client
$client = new fXmlRpc\Client(
    'http://127.0.0.1:9001/RPC2',
    new fXmlRpc\Transport\PsrTransport(
        new GuzzleHttp\Psr7\HttpFactory(),
        $guzzleClient
    )
);

// Or, if connecting via a Unix Domain Socket
$guzzleClient = new \GuzzleHttp\Client([
    'curl' => [
        \CURLOPT_UNIX_SOCKET_PATH => '/var/run/supervisor.sock',
    ],
]);

$client = new fXmlRpc\Client(
    'http://localhost/RPC2',
    new fXmlRpc\Transport\PsrTransport(
        new GuzzleHttp\Psr7\HttpFactory(),
        $guzzleClient
    )
);

// Pass the client to the Supervisor library.
$supervisor = new Supervisor\Supervisor($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();

/** @var \Supervisor\Supervisor $supervisor */

try {
	$supervisor->startProcess('process', true);
} catch (\Supervisor\Exception\Fault\BadNameException $e) {
	// handle bad name error here
} catch (\Supervisor\Exception\SupervisorException $e) {
	// handle any other errors here
}