meskin/nailgun-php

A PHP Nailgun client

dev-master 2019-07-10 10:52 UTC

This package is auto-updated.

Last update: 2024-04-18 01:57:36 UTC


README

A php Nailgun client API.

The Nailgun client API lets you run java code in Nailgun directly from PHP.

PHP from Packagist (specify version) Build Status codecov

Install

composer require meskin/nailgun-php

Examples

<?php

require "./vendor/autoload.php";

$client = new Nailgun\Client();
$client->connect('127.0.0.1', 2113);

$result = $client->run("com.facebook.nailgun.examples.HelloWorld");
$client->disconnect();

print 'Exit Code : ' . $result->getExitCode() . PHP_EOL;

if ($result->successful()) {
    print $result->getOutput();
} else {
    print $result->getError();
}
<?php

require "./vendor/autoload.php";

$client = new Nailgun\Client();
$client->connect('127.0.0.1', 2113);

$options = [
    'output' => fopen("php://stdout", "w"),
    'error'  => fopen("php://stderr", "w"),
];
$result = $client->run("com.facebook.nailgun.examples.ThreadTest", $options);
$client->disconnect();

print 'Exit Code : ' . $result->getExitCode() . PHP_EOL;
<?php

require "./vendor/autoload.php";

$client = new Nailgun\Client();
$client->connect('127.0.0.1', 2113);

$options = [
    'input'     => fopen("file:///tmp/input", "r"), // OR "String"
    'arguments' => ['MD5'],
];
$result = $client->run("com.facebook.nailgun.examples.Hash", $options);
$client->disconnect();

print 'Hash : ' . $result->getOutput() . PHP_EOL;
<?php
require "./vendor/autoload.php";

$client = new Nailgun\Client();
$client->connect('127.0.0.1', 2113);

$options = [
    'output'       => fopen("file:///tmp/output", "a+"),
    'error'        => fopen("file:///tmp/error", "a+"),
    'directory'    => '/home/alireza/projects/',
    'arguments'    => ['arg1', 'arg2', 'arg3'],
    'environments' => [
        'HOME' => '/home/alireza'
    ],
];
$result = $client->run("com.facebook.nailgun.examples.DumpAll", $options);
$client->disconnect();

echo $result->getExitCode();