PHP code example of knik / gameap-daemon-client
1. Go to this page and download the library: Download knik/gameap-daemon-client 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/ */
knik / gameap-daemon-client example snippets
$gdaemonCommands = new GdaemonCommands([
'host' => 'localhost',
'port' => 31717,
'serverCertificate' => '/path/to/server.crt',
'localCertificate' => '/path/to/client.crt',
'privateKey' => '/path/to/client.key.pem',
'privateKeyPass' => '1234',
'timeout' => 10,
'workDir' => '/home/user',
]);
$gdaemonCommands->connect();
$result = $gdaemonCommands->exec('echo HELLO');
var_dump($result); // string(5) "HELLO"
$result = $gdaemonCommands->exec('echo HELLO', $exitCode);
var_dump($result); // string(5) "HELLO"
var_dump($exitCode); // int(0)
$gdaemonFiles = new GdaemonFiles([
'host' => 'localhost',
'port' => 31717,
'serverCertificate' => '/path/to/server.crt',
'localCertificate' => '/path/to/client.crt',
'privateKey' => '/path/to/client.key.pem',
'privateKeyPass' => '1234',
'timeout' => 10,
]);
$gdaemonFiles->connect();
$result = $gdaemonFiles->directoryContents('/path/to/dir');
print_r($result);
/*
Array
(
[0] => Array
(
[name] => directory
[size] => 0
[mtime] => 1542013640
[type] => dir
[permissions] => 0755
)
[1] => Array
(
[name] => file.txt
[size] => 15654
[mtime] => 1542013150
[type] => file
[permissions] => 0644
)
)
*/
$result = $gdaemonFiles->listFiles('/path/to/dir');
print_r($result);
Array
(
[0] => directory
[1] => file.txt
)
$gdaemonFiles->mkdir('/path/to/new_dir');
$gdaemonFiles->delete('/path/to/file.txt');
$gdaemonFiles->delete('/path/to/file.txt', true);
$gdaemonFiles->rename('/path/to/file.txt', '/path/to/new_name.txt');
$gdaemonFiles->copy('/path/to/file.txt', '/path/to/new_file.txt');
$gdaemonFiles->chmod(0755, '/path/to/file.txt');
$gdaemonFiles->exist('/path/to/file.txt');
$result = $gdaemonFiles->directoryContents('/path/to/file.txt');
print_r($result);
/*
Array
(
[name] => file.txt
[size] => 43
[type] => file
[mtime] => 1541971363
[atime] => 1541971363
[ctime] => 1541971363
[permissions] => 0644
[mimetype] => text/plain
)
*/
$gdaemonFiles->get('/remote/path/to/file.txt', '/local/path/to/file.txt');
$fileHandle = fopen('php://temp', 'w+b');
$gdaemonFiles->get('/remote/path/to/file.txt', $fileHandle);
$gdaemonFiles->put('/local/path/to/file.txt', '/remote/path/to/file.txt');
$fileHandle = fopen('/local/path/to/file.txt', 'r');
$gdaemonFiles->put($fileHandle, '/remote/path/to/file.txt');
$gdaemonStatus = new GdaemonStatus([
'host' => 'localhost',
'port' => 31717,
'serverCertificate' => '/path/to/server.crt',
'localCertificate' => '/path/to/client.crt',
'privateKey' => '/path/to/client.key.pem',
'privateKeyPass' => '1234',
'timeout' => 10,
]);
$gdaemonStatus->connect();
$version = $gdaemonStatus->version();
$info = $gdaemonStatus->infoBase();
$info = $gdaemonStatus->infoDetails();