PHP code example of muxx / dplr

1. Go to this page and download the library: Download muxx/dplr 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/ */

    

muxx / dplr example snippets




$dplr = new Dplr\Dplr('ssh-user', '/path/to/GoSSHa');

$dplr
    ->addServer('front1.site.ru', 'front')
    ->addServer('front2.site.ru', 'front')
    ->addServer('job1.site.ru', ['job', 'master'])
    ->addServer('job2.site.ru', 'job')
;

const PATH = '/home/webmaster/product';

$dplr
    ->upload('/path/to/local_file1', '/path/to/remote_file1', 'front')
    ->command(PATH . '/app/console cache:clear')
;

$dplr->run(function($step) {
    echo $step;
});

if (!$dplr->isSuccessful()) {
    echo "Deploy completed with errors.\n";
    foreach($dplr->getFailed() as $item) {
        echo "[ " . $item . " ]\n" . $item->getErrorOutput() . "\n";
    }
}
else {
    echo "Deploy completed successfully.\n";
}

$report = $dplr->getReport();
echo sprintf(
    "Tasks: %s total, %s successful, %s failed.\nTime of execution: %s\n",
    $report['total'],
    $report['successful'],
    $report['failed'],
    $report['timers']['execution']
);

$dplr = new Dplr\Dplr('ssh-user', '/path/to/GoSSHa');

// or

$dplr = new Dplr\Dplr('ssh-user', '/path/to/GoSSHa', '/path/to/public.key');

$dplr->addServer('1.2.3.4'); // Add server IP 1.2.3.4 without adding to group
$dplr->addServer('1.2.3.5', 'app'); // Add server IP 1.2.3.5 with adding to group 'app'
$dplr->addServer('1.2.3.6', ['app', 'cache']); // Add server IP 1.2.3.6 with adding to groups 'app' and 'cache'
$dplr->addServer('1.2.3.7:2222', ['cache']); // Add server IP 1.2.3.7 and ssh port 2222 with adding to group 'cache'

$local = __DIR__;
$path = '/home/webmaster/project';

$dplr
    ->upload("$local/share/parameters.yml", "$path/app/config/parameters.yml")
    ->command("cd $path && ./app/console cache:clear --env=prod --no-debug", 'app', 15)
;

$dplr
    ->command('app build')
    ->multi()
        ->command('app init --mode=job', 'job')
        ->command('app init --mode=app', 'front')
    ->end()
    ->command('app run', 'front')
;

$dplr->run();

$dplr->run(function($step) {
    echo $step;
});

/*
    Output
    --
    CPY /home/webmaster/test/share/parameters.yml -> /home/webmaster/project/app/config/parameters.yml ..T.
    CMD cd /home/webmaster/project && ./app/console doctrine:migration:migrate --env=prod --no-debug .E
*/

$report = $dplr->getReport();
echo sprintf(
    "Tasks: %s total, %s successful, %s failed.\nTime of execution: %s\n",
    $report['total'],
    $report['successful'],
    $report['failed'],
    $report['timers']['execution']
);

/*
    Output
    --
    Tasks: 163 total, 163 successful, 0 failed.
    Time of execution: 08:25
*/

foreach($dplr->getReports() as $report) {
    echo sprintf(
        "%s\n    Successful: %s\n",
        (string) $report,
        $report->isSuccessful() ? 'true' : 'false'
    );
}

/*
    Output
    --
    CPY /home/webmaster/test/share/parameters.yml -> /home/webmaster/project/app/config/parameters.yml | 54.194.27.92
        Successful: false
    CMD cd /home/webmaster/project && ./app/console doctrine:migration:migrate --env=prod --no-debug | 54.194.27.92
        Successful: true
*/