Помогите. Скрипт сбрасывает соединение после его выполнения.
include 'PleskApiClient.php';
$host = 'localhost';
$login = 'root';
$password = 'pass';
$client = new PleskApiClient($host);
$client->setCredentials($login, $password);
$request = '
<packet>
<webspace>
<add>
<gen_setup>
<name>domain.com</name>
<owner-login>login</owner-login>
<htype>vrt_hst</htype>
<ip_address>192.168.0.1</ip_address>
<status>0</status>
</gen_setup>
<hosting>
<vrt_hst>
<property>
<name>ftp_login</name>
<value>ftp_login</value>
</property>
<property>
<name>ftp_password</name>
<value>ftp_password</value>
</property>
<ip_address>192.168.0.1</ip_address>
</vrt_hst>
</hosting>
<plan-name>Тариф</plan-name>
</add>
<sync-subscription>
<filter>
<name>domain.com</name>
</filter>
</sync-subscription>
</webspace>
</packet>
';
$response = $client->request($request);
print $response;
PleskApiClient.php:
/**
* Client for Plesk API-RPC
*/
class PleskApiClient
{
private $_host;
private $_port;
private $_protocol;
private $_login;
private $_password;
private $_secretKey;
/**
* Create client
*
* @param string $host
* @param int $port
* @param string $protocol
*/
public function __construct($host, $port = 8443, $protocol = 'https')
{
$this->_host = $host;
$this->_port = $port;
$this->_protocol = $protocol;
}
/**
* Setup credentials for authentication
*
* @param string $login
* @param string $password
*/
public function setCredentials($login, $password)
{
$this->_login = $login;
$this->_password = $password;
}
/**
* Define secret key for alternative authentication
*
* @param string $secretKey
*/
public function setSecretKey($secretKey)
{
$this->_secretKey = $secretKey;
}
/**
* Perform API request
*
* @param string $request
* @return string
*/
public function request($request)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "$this->_protocol://$this->_host:$this->_port/enterprise/control/agent.php");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->_getHeaders());
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
/**
* Retrieve list of headers needed for request
*
* @return array
*/
private function _getHeaders()
{
$headers = array(
"Content-Type: text/xml",
"HTTP_PRETTY_PRINT: TRUE",
);
if ($this->_secretKey) {
$headers[] = "KEY: $this->_secretKey";
} else {
$headers[] = "HTTP_AUTH_LOGIN: $this->_login";
$headers[] = "HTTP_AUTH_PASSWD: $this->_password";
}
return $headers;
}
}