-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.php
66 lines (59 loc) · 2.11 KB
/
client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/*
* This file is part of XRL, a simple XML-RPC Library for PHP.
*
* Copyright (c) 2012, XRL Team. All rights reserved.
* XRL is licensed under the 3-clause BSD License.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
* This example expects an XML-RPC server providing a "hello"
* procedure and supporting XML-RPC introspection. The server
* should be served from a file called "server.php" in the
* same folder as this script.
*
* WARNING!
* This script will not run properly when served from PHP's
* built-in web server since the built-in web server
* does not support concurrent requests.
*
* When run under the built-in web server, it will just appear
* to hang until it dies with the following warning in the console:
*
* PHP Warning: XMLReader::open(http://xxx/server.php):
* failed to open stream: HTTP request failed!
*
*
* This script will automatically generate the URL required
* to query the XML-RPC server by substituting this script's
* filename with "server.php". For example:
*
* Client: http://localhost/xmlrpc/client.php
* Server: http://localhost/xmlrpc/server.php
*
* Client: https://foobar.example.com:4443/tests/xrl/client.php/foo.bar?baz=1
* Server: https://foobar.example.com:4443/tests/xrl/server.php
*/
require_once(
dirname(dirname(__DIR__)) .
DIRECTORY_SEPARATOR . 'src' .
DIRECTORY_SEPARATOR . 'Autoload.php'
);
\fpoirotte\XRL\Autoload::register();
// Create the URL that will be used to contact the XML-RPC server.
$pos = strrpos($_SERVER['SCRIPT_NAME'], '/');
$serverUrl = (!empty($_SERVER['HTTP_SSL']) &&
strcasecmp($_SERVER['HTTP_SSL'], 'off'))
? 'https'
: 'http';
$serverUrl .= '://'.$_SERVER['HTTP_HOST'];
$serverUrl .= (string) substr($_SERVER['SCRIPT_NAME'], 0, $pos);
$serverUrl .= '/server.php';
// Create a new client.
$client = new \fpoirotte\XRL\Client($serverUrl);
// List all available procedures.
var_dump($client->{'system.listMethods'}());
// Say hello :)
var_dump($client->hello('world'));