VestaCP api与CURL Giving 500错误

时间:2016-02-15 11:01:15

标签: php curl vesta

这是我的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 [错误] 14102#0:* 6上游过早关闭   从上游,客户端读取响应头时连接:   86.6.39.173,server:testing.DOMAIN.co.uk,请求:“POST /suspendUser.php HTTP / 1.1”,上游:   “http://45.58.48.103:8080/suspendUser.php”,主持人:   “testing.DOMAIN.co.uk”,推荐人:“http://testing.DOMAIN.co.uk/

我已使用DOMAIN

替换了我的域名

1 个答案:

答案 0 :(得分:1)

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