2013-04-30 91 views
0

我正在使用Curl连接到服务器并使用以下功能更新数据。该功能工作很好,并更新约400条记录。之后它会抛出一个错误,请告知如何解决这个问题?致命错误:在/var/www/vhosts/abc.com/中出现未被捕获的异常消息'无法连接到主机'

Fatal error: Uncaught exception with message 'couldn't connect to host' in /var/www/vhosts/abc.com/ 

comm_Api_Connection->put('https://www.vam...', Object(stdClass)) #2 /var/www/vhosts/abc.com/httpdocs/mysite/demo/comm-common1/Api.php(1530): 

comm_Api::updateResource('/products/5250', Array) #3 /var/www/vhosts/abc.com/httpdocs/mysite/demo/sync_prod_inventory_new1.php(1088): 

comm_Api::updateProduct('5250', Array) #4 {main} thrown in /var/www/vhosts/abc.com/httpdocs/mysite/demo/comm-common1/Api.php on line 204 

PHP函数如下:

<?php 
public function put($url, $body) 
{ 
    $this->addHeader('Content-Type', $this->getContentType()); 

    if (!is_string($body)) { 
     $body = json_encode($body); 
    } 

    $this->initializeRequest(); 

    $handle = tmpfile(); 
    fwrite($handle, $body); 
    fseek($handle, 0); 

    curl_setopt($this->curl, CURLOPT_INFILE, $handle); 
    curl_setopt($this->curl, CURLOPT_INFILESIZE, strlen($body)); 
    curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'PUT'); 
    curl_setopt($this->curl, CURLOPT_URL, $url); 
    curl_setopt($this->curl, CURLOPT_PUT, true); 
    curl_exec($this->curl); 

    return $this->handleResponse(); 
} 

回答

1

在必要的时候我会说你是开到服务器

每次连接太多,你调用这个方法你打开一个新的请求,但不要关闭它。直到达到

超时将继续开放,如果你的服务器只允许400个并发连接,第400调用方法后事情会失败

你需要每个请求后关闭连接

curl_close($ch) 
+0

我试过像这样 curl_exec($ this-> curl); curl_close($ this-> curl); return $ this-> handleResponse(); } 它没有工作相同的错误 – user580950 2013-04-30 14:16:36

1

我认为你的curl需要SSL验证。

请把下面一行在你卷曲代码

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

这条线路是通过“真”是你请求的URL是HTTPS,否则它的“假”。

在你的情况,我认为这是真的。 请传递真实参数并检查它。

相关问题