2013-04-30 90 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,否則它的「假」。

在你的情況,我認爲這是真的。 請傳遞真實參數並檢查它。

相關問題