VestaCP api with CURL Giving 500 error

VestaCP api with CURL Giving 500 error

这是我的 Vesta.php 我做这个是为了发送 API 请求并在内部使用它

<?php
require 'includes/Config.php';
class VestaAPI {
    private $_instance = null;
    public static function getInstance() {
        if ($_instance == null) {
            $_instance = new VestaAPI();
        }
        return $_instance;
    }
    public static function runCMD($cmd,$arg1 = "",$arg2 = "",$arg3 = "",$arg4 = "",$arg5 = "",$arg6 = "",$arg7 = "",$arg8 = "",$arg9 = "",$arg10 = ""){
    ini_set('max_execution_time', 30);
set_time_limit(30);
        // Server credentials
    $settings = Config::getInstance()->getSettings();
$vst_hostname = $settings["vestaLogin"]["Host"];
$vst_username = $settings["vestaLogin"]["Username"];
$vst_password = $settings["vestaLogin"]["Password"];
$vst_command = $cmd;


// Prepare POST query
$postvars = array(
    'user' => $vst_username,
    'password' => $vst_password,
    'cmd' => $vst_command,
    'arg1' => $arg1,
    'arg2' => $arg2
);
$postdata = http_build_query($postvars);

// Send POST query via cURL
$postdata = http_build_query($postvars);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://' . $vst_hostname . ':81/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 1);   // cancel if below 1 byte/second
curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 30);   // for a period of 30 seconds
 curl_setopt($post, CURLOPT_AUTOREFERER, true);
    curl_setopt($post, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($post, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt($post, CURLOPT_TIMEOUT, 30 );
    curl_setopt(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
return curl_exec($curl);
    }
public static function arrayToXml($array, &$xml){
    foreach ($array as $key => $value) {
        if(is_array($value)){
            if(is_int($key)){
                $key = "e";
            }
            $label = $xml->addChild($key);
            arrayToXml($value, $label);
        }
        else {
            $xml->addChild($key, $value);
        }
    }
}
}

// to get your instance use

?>

但是当我在此处尝试 运行 此代码(暂停网站或取消暂停)时,我收到错误 500

<?php
require 'includes/Vesta.php';
if(isset($_POST["username"])){}else{die("ERROR 403");}
$output = VestaAPI::runCMD("v-suspend-user",$_POST["username"]);
if(strstr($output, "Error:")) {die($output);}else{
    die("Done!");
}
?>

但如果我正在获取帐户数据,我认为这一定是超时问题,但这是 php 错误日志

2016/02/15 00:53:55 [error] 14102#0: *6 upstream prematurely closed connection while reading response header from upstream, client: 86.6.39.173, server: testing.DOMAIN.co.uk, request: "POST /suspendUser.php HTTP/1.1", upstream: "http://45.58.48.103:8080/suspendUser.php", host: "testing.DOMAIN.co.uk", referrer: "http://testing.DOMAIN.co.uk/"

我已将我的域替换为 DOMAIN

也许您 运行 API 请求来自与 vestacp 安装相同的服务器。 发生这种情况是因为在 suspend/unsuspend 用户之后,vestacp Web 服务重新启动。 您必须设置 $arg2='no',以防止 Web 服务重新启动,并在稍后重新启动它。