API Documentation RunningExamples server.list servers PHP
Aus EUserv Wiki
(Unterschied zwischen Versionen)
Root (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „back to API Documentation <nowiki> <?php //includes the class library include_once("lib/xmlrpc.inc"); $xmlrpc_internalencoding = 'UTF-8'; $host="api.test.e…“) |
Root (Diskussion | Beiträge) |
||
(Der Versionsvergleich bezieht 1 dazwischenliegende Version mit ein.) | |||
Zeile 1: | Zeile 1: | ||
- | back to [[API Documentation]] | + | back to [[API_Documentation#PHP_EXAMPLE_3|API Documentation]] |
- | + | = server.list_servers = | |
<nowiki> | <nowiki> | ||
<?php | <?php | ||
+ | |||
//includes the class library | //includes the class library | ||
include_once("lib/xmlrpc.inc"); | include_once("lib/xmlrpc.inc"); | ||
$xmlrpc_internalencoding = 'UTF-8'; | $xmlrpc_internalencoding = 'UTF-8'; | ||
+ | |||
$host="api.test.euserv.net"; | $host="api.test.euserv.net"; | ||
$port=443; | $port=443; | ||
Zeile 11: | Zeile 13: | ||
$password="<API_USER_PASSWORD>"; | $password="<API_USER_PASSWORD>"; | ||
$api_path="/"; | $api_path="/"; | ||
+ | |||
//defines the function | //defines the function | ||
function server_list_servers($host,$port,$username,$password,$api_path) | function server_list_servers($host,$port,$username,$password,$api_path) | ||
{ | { | ||
- | //creates the serverurl | + | |
- | $serverurl = 'https://'.$host.':'.$port.'/'.$api_path; | + | //creates the serverurl |
- | //----------creates the message which will be send to the server---------- | + | $serverurl = 'https://'.$host.':'.$port.'/'.$api_path; |
- | //creates the request for the XML-RPC Server | + | |
- | $request = new xmlrpcmsg('server.list_servers'); | + | //----------creates the message which will be send to the server---------- |
- | //adds parameters to the request | + | |
- | $request->addParam | + | //creates the request for the XML-RPC Server |
- | ( | + | $request = new xmlrpcmsg('server.list_servers'); |
- | //creates a value of type struct which contains an array with the username and password | + | |
- | new xmlrpcval | + | //adds parameters to the request |
- | ( | + | $request->addParam |
- | array | + | ( |
- | ( | + | |
- | //creates a value of type string which contains the "$username" | + | //creates a value of type struct which contains an array with the username and password |
- | 'login' => new xmlrpcval($username, 'string'), | + | new xmlrpcval |
- | //creates a value of type string which contains the "$password" | + | ( |
- | 'password' => new xmlrpcval($password, 'string'), | + | array |
- | ) | + | |
- | ,'struct' | + | ( |
- | ) | + | //creates a value of type string which contains the "$username" |
- | ); | + | 'login' => new xmlrpcval($username, 'string'), |
- | //----------creates the XML-RPC client which represents a client of a XML-RPC server---------- | + | |
- | //creates the client | + | //creates a value of type string which contains the "$password" |
- | $client = new xmlrpc_client($serverurl); | + | 'password' => new xmlrpcval($password, 'string'), |
- | //disable SSL Keycheck | + | |
- | $client->setSSLVerifyPeer(0); | + | ) |
- | //----------sends the request to the server and gets the response---------- | + | ,'struct' |
- | //sends the request via https and writes it into $response. timeout is set to 0 | + | ) |
- | $response = $client->send($request,0,'https'); | + | ); |
- | //generates a storable representation of $response and writes it into $result_xml | + | |
- | //$result_xml = $response->serialize(); | + | //----------creates the XML-RPC client which represents a client of a XML-RPC server---------- |
- | //checks the response. if the method "faultCode" returns zero, the response was succesfull | + | |
- | if (0==$response->faultCode()) | + | //creates the client |
- | { | + | $client = new xmlrpc_client($serverurl); |
- | //returns the value sent by the server | + | |
- | $value = $response->value(); | + | //disable SSL Keycheck |
- | //returns the actual PHP-language value of "value" | + | $client->setSSLVerifyPeer(0); |
- | $result_obj = $value->scalarval(); | + | |
- | //destroys "value" | + | //----------sends the request to the server and gets the response---------- |
- | unset($value); | + | |
- | } | + | //sends the request via https and writes it into $response. timeout is set to 0 |
- | else | + | $response = $client->send($request,0,'https'); |
- | { | + | |
- | //returns the faultCode and the faultString | + | //generates a storable representation of $response and writes it into $result_xml |
- | return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString()); | + | //$result_xml = $response->serialize(); |
- | } | + | |
- | //destroys "client" | + | //checks the response. if the method "faultCode" returns zero, the response was succesfull |
- | unset($client); | + | if (0==$response->faultCode()) |
- | //destroys "response" | + | { |
- | unset($response); | + | //returns the value sent by the server |
- | //----------reads the result_obj---------- | + | $value = $response->value(); |
- | //if result_obj is set then it returns the actual PHP-language value of "result_obj" | + | |
- | if (isset($result_obj['status'])) | + | //returns the actual PHP-language value of "value" |
- | { | + | $result_obj = $value->scalarval(); |
- | $value['status'] = $result_obj['status']->scalarval(); | + | |
- | } | + | //destroys "value" |
- | if (isset($result_obj['server_list_count'])) | + | unset($value); |
- | { | + | } |
- | $value['server_list_count'] = $result_obj['server_list_count']->scalarval(); | + | else |
- | } | + | { |
- | if (isset($result_obj['server_list_data'])) | + | //returns the faultCode and the faultString |
- | { | + | return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString()); |
- | $i=0; | + | } |
- | //reads the data | + | |
- | do | + | //destroys "client" |
- | { | + | unset($client); |
- | //gets the server_order_number | + | |
- | $number = $result_obj['server_list_data']->structEach(); | + | //destroys "response" |
- | $i=$i+1; | + | unset($response); |
- | $data = $result_obj['server_list_data']->scalarval(); | + | |
- | //reads the value off the server_order_number | + | |
- | $data = $data[$number[0]]->scalarval(); | + | //----------reads the result_obj---------- |
- | //reads the value of each member and writes it into an array | + | |
- | $server_list_data[$number[0]]['srv_name'] = $data['srv_name']->scalarval(); | + | //if result_obj is set then it returns the actual PHP-language value of "result_obj" |
- | $server_list_data[$number[0]]['srv_id'] = $data['srv_id']->scalarval(); | + | |
- | $server_list_data[$number[0]]['order_desc'] = $data['order_desc']->scalarval(); | + | if (isset($result_obj['status'])) |
- | $server_list_data[$number[0]]['srv_main_ip'] = $data['srv_main_ip']->scalarval(); | + | { |
- | $server_list_data[$number[0]]['status'] = $data['status']->scalarval(); | + | $value['status'] = $result_obj['status']->scalarval(); |
- | } | + | } |
- | while($i<$value['server_list_count']); | + | if (isset($result_obj['server_list_count'])) |
- | //writes the array "server_list_data" into the array "value" | + | { |
- | $value['server_list_data'] = $server_list_data; | + | $value['server_list_count'] = $result_obj['server_list_count']->scalarval(); |
- | } | + | } |
- | return $value; | + | |
+ | if (isset($result_obj['server_list_data'])) | ||
+ | { | ||
+ | $i=0; | ||
+ | |||
+ | //reads the data | ||
+ | do | ||
+ | { | ||
+ | //gets the server_order_number | ||
+ | $number = $result_obj['server_list_data']->structEach(); | ||
+ | $i=$i+1; | ||
+ | |||
+ | $data = $result_obj['server_list_data']->scalarval(); | ||
+ | |||
+ | //reads the value off the server_order_number | ||
+ | $data = $data[$number[0]]->scalarval(); | ||
+ | |||
+ | //reads the value of each member and writes it into an array | ||
+ | $server_list_data[$number[0]]['srv_name'] = $data['srv_name']->scalarval(); | ||
+ | $server_list_data[$number[0]]['srv_id'] = $data['srv_id']->scalarval(); | ||
+ | $server_list_data[$number[0]]['order_desc'] = $data['order_desc']->scalarval(); | ||
+ | $server_list_data[$number[0]]['srv_main_ip'] = $data['srv_main_ip']->scalarval(); | ||
+ | $server_list_data[$number[0]]['status'] = $data['status']->scalarval(); | ||
+ | |||
+ | } | ||
+ | while($i<$value['server_list_count']); | ||
+ | |||
+ | //writes the array "server_list_data" into the array "value" | ||
+ | $value['server_list_data'] = $server_list_data; | ||
+ | } | ||
+ | return $value; | ||
} | } | ||
+ | |||
//calls the function | //calls the function | ||
$result = server_list_servers($host,$port,$username,$password,$api_path); | $result = server_list_servers($host,$port,$username,$password,$api_path); | ||
+ | |||
if(0==$result['faultCode']) | if(0==$result['faultCode']) | ||
{ | { | ||
- | echo "Status: ".$result['status']." server_list_count: ".$result['server_list_count']."<br><br>"; | + | echo "Status: ".$result['status']." server_list_count: ".$result['server_list_count']."<br><br>"; |
- | //writes the array "server_list_data" into "daten" | + | |
- | $daten = $result["server_list_data"]; | + | //writes the array "server_list_data" into "daten" |
- | //gets the array_keys(members) of "daten" | + | $daten = $result["server_list_data"]; |
- | $datenkeys = array_keys($daten); | + | |
- | $k=0; | + | //gets the array_keys(members) of "daten" |
- | //counts the arraykeys, the number of arraykeys will be used in the do-while construct | + | $datenkeys = array_keys($daten); |
- | $anzahlkeys = count($datenkeys); | + | |
- | do | + | $k=0; |
- | { | + | //counts the arraykeys, the number of arraykeys will be used in the do-while construct |
- | //outputs the data | + | $anzahlkeys = count($datenkeys); |
- | echo " <u>server_order_number:</u> ".$datenkeys[$k]; | + | do |
- | echo " <u>srv_name:</u> ".$daten[$datenkeys[$k]]['srv_name']; | + | { |
- | echo " <u>srv_id:</u> ".$daten[$datenkeys[$k]]['srv_id']; | + | //outputs the data |
- | echo " <u>order_desc:</u> ".$daten[$datenkeys[$k]]['order_desc']; | + | echo " <u>server_order_number:</u> ".$datenkeys[$k]; |
- | echo " <u>srv_main_ip:</u> ".$daten[$datenkeys[$k]]['srv_main_ip']; | + | echo " <u>srv_name:</u> ".$daten[$datenkeys[$k]]['srv_name']; |
- | echo " <u>status:</u> ".$daten[$datenkeys[$k]]['status']; | + | echo " <u>srv_id:</u> ".$daten[$datenkeys[$k]]['srv_id']; |
- | echo "<br>"; | + | echo " <u>order_desc:</u> ".$daten[$datenkeys[$k]]['order_desc']; |
- | $k=$k+1; | + | echo " <u>srv_main_ip:</u> ".$daten[$datenkeys[$k]]['srv_main_ip']; |
- | } | + | echo " <u>status:</u> ".$daten[$datenkeys[$k]]['status']; |
+ | echo "<br>"; | ||
+ | $k=$k+1; | ||
+ | |||
+ | } | ||
while($k<$anzahlkeys); | while($k<$anzahlkeys); | ||
} | } | ||
else | else | ||
{ | { | ||
- | echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString']; | + | echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString']; |
} | } | ||
?> | ?> | ||
</nowiki> | </nowiki> |
Aktuelle Version vom 07:26, 6. Sep. 2012
back to API Documentation
server.list_servers
<?php //includes the class library include_once("lib/xmlrpc.inc"); $xmlrpc_internalencoding = 'UTF-8'; $host="api.test.euserv.net"; $port=443; $username="<API_USER>"; $password="<API_USER_PASSWORD>"; $api_path="/"; //defines the function function server_list_servers($host,$port,$username,$password,$api_path) { //creates the serverurl $serverurl = 'https://'.$host.':'.$port.'/'.$api_path; //----------creates the message which will be send to the server---------- //creates the request for the XML-RPC Server $request = new xmlrpcmsg('server.list_servers'); //adds parameters to the request $request->addParam ( //creates a value of type struct which contains an array with the username and password new xmlrpcval ( array ( //creates a value of type string which contains the "$username" 'login' => new xmlrpcval($username, 'string'), //creates a value of type string which contains the "$password" 'password' => new xmlrpcval($password, 'string'), ) ,'struct' ) ); //----------creates the XML-RPC client which represents a client of a XML-RPC server---------- //creates the client $client = new xmlrpc_client($serverurl); //disable SSL Keycheck $client->setSSLVerifyPeer(0); //----------sends the request to the server and gets the response---------- //sends the request via https and writes it into $response. timeout is set to 0 $response = $client->send($request,0,'https'); //generates a storable representation of $response and writes it into $result_xml //$result_xml = $response->serialize(); //checks the response. if the method "faultCode" returns zero, the response was succesfull if (0==$response->faultCode()) { //returns the value sent by the server $value = $response->value(); //returns the actual PHP-language value of "value" $result_obj = $value->scalarval(); //destroys "value" unset($value); } else { //returns the faultCode and the faultString return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString()); } //destroys "client" unset($client); //destroys "response" unset($response); //----------reads the result_obj---------- //if result_obj is set then it returns the actual PHP-language value of "result_obj" if (isset($result_obj['status'])) { $value['status'] = $result_obj['status']->scalarval(); } if (isset($result_obj['server_list_count'])) { $value['server_list_count'] = $result_obj['server_list_count']->scalarval(); } if (isset($result_obj['server_list_data'])) { $i=0; //reads the data do { //gets the server_order_number $number = $result_obj['server_list_data']->structEach(); $i=$i+1; $data = $result_obj['server_list_data']->scalarval(); //reads the value off the server_order_number $data = $data[$number[0]]->scalarval(); //reads the value of each member and writes it into an array $server_list_data[$number[0]]['srv_name'] = $data['srv_name']->scalarval(); $server_list_data[$number[0]]['srv_id'] = $data['srv_id']->scalarval(); $server_list_data[$number[0]]['order_desc'] = $data['order_desc']->scalarval(); $server_list_data[$number[0]]['srv_main_ip'] = $data['srv_main_ip']->scalarval(); $server_list_data[$number[0]]['status'] = $data['status']->scalarval(); } while($i<$value['server_list_count']); //writes the array "server_list_data" into the array "value" $value['server_list_data'] = $server_list_data; } return $value; } //calls the function $result = server_list_servers($host,$port,$username,$password,$api_path); if(0==$result['faultCode']) { echo "Status: ".$result['status']." server_list_count: ".$result['server_list_count']."<br><br>"; //writes the array "server_list_data" into "daten" $daten = $result["server_list_data"]; //gets the array_keys(members) of "daten" $datenkeys = array_keys($daten); $k=0; //counts the arraykeys, the number of arraykeys will be used in the do-while construct $anzahlkeys = count($datenkeys); do { //outputs the data echo " <u>server_order_number:</u> ".$datenkeys[$k]; echo " <u>srv_name:</u> ".$daten[$datenkeys[$k]]['srv_name']; echo " <u>srv_id:</u> ".$daten[$datenkeys[$k]]['srv_id']; echo " <u>order_desc:</u> ".$daten[$datenkeys[$k]]['order_desc']; echo " <u>srv_main_ip:</u> ".$daten[$datenkeys[$k]]['srv_main_ip']; echo " <u>status:</u> ".$daten[$datenkeys[$k]]['status']; echo "<br>"; $k=$k+1; } while($k<$anzahlkeys); } else { echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString']; } ?>