2010-05-07 70 views
0

我得到在我的Zend應用這個奇怪的錯誤使用這段代碼:使用在Zend中的應用curl_init導致會話錯誤

 
$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, 'www.xyz.com/ab.php'); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
$data = curl_exec($curl); 
curl_close($curl);  

if (!isset($location->country)) { 
$location = new Zend_Session_Namespace('location'); 
$xml = new SimpleXMLElement($data); 
$location->city=$xml->City; 
} 

這是錯誤的,我得到:

 
Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'session has already been started by session.auto-start or session_start() 

當我刪除代碼一切正常。 任何想法?

編輯:關於進一步的調試,我發現這個錯誤並不是因爲捲髮代碼 - 當我分配$ location-> city = $ xml-> City時發生錯誤; 但是,當我將該行更改爲$ location-> city =''。$ xml-> City。''; 它開始工作..........這讓我瘋狂!

回答

1

不太清楚你的問題是什麼,但我可以告訴你,Zend_Http_Client非常好,強大,它支持多種適配器,包括CURL。

例子:

$http = new Zend_Http_Client(
    'url', 
    $this->options 
); 
$response = $http->request(); 

http://framework.zend.com/manual/en/zend.http.html

+0

謝謝我將檢查出 – Gublooo 2010-05-07 06:30:34

0

new Zend_Session_Namespace('location');通話將嘗試啓動一個新的會話,但顯然一個已經不使用Zend_Session電話開始,因此它拋出一個異常。因此,檢查你的代碼(和php.ini)的其餘部分以找出你開始會話的位置(這可能是因爲php.ini中的session.auto_start = 1或某個session_start()調用)並按照你的看法修復它適合...

+0

感謝您的迴應 - 這就是我的想法和我在谷歌上的搜索也使我得出了同樣的結論 - 但看到我上面的編輯部分 - 當我做出改變一切開始工作很好 - 對我來說,連接是什麼似乎很奇怪 – Gublooo 2010-05-08 18:12:41

相關問題