2013-04-02 32 views
0

當我嘗試通過瀏覽器訪問.php文件時,在我的本地wamp服務器上運行此操作會給我ERR_CONNECTION_RESET。這裏發生了什麼?爲什麼這個簡單的PHP腳本崩潰?

<?php 
$catalog = simplexml_load_file('http://www.w3schools.com/xml/cd_catalog.xml'); 

session_start(); 

if (!isset($_SESSION['selection'])) { 
    $_SESSION['selection'] = array(); 
} 

array_push($_SESSION['selection'], $catalog->CD[0]); 
?> 

這裏有一塊var_dump($catalog)

object(SimpleXMLElement)[1] 
    public 'CD' => 
    array (size=26) 
     0 => 
     object(SimpleXMLElement)[2] 
      public 'TITLE' => string 'Empire Burlesque' (length=16) 
      public 'ARTIST' => string 'Bob Dylan' (length=9) 
      public 'COUNTRY' => string 'USA' (length=3) 
      public 'COMPANY' => string 'Columbia' (length=8) 
      public 'PRICE' => string '10.90' (length=5) 
      public 'YEAR' => string '1985' (length=4) 
     1 => [...] 

編輯的輸出: 的建議發現這個從看在Apache日誌:

[Tue Apr 02 09:34:54 2013] [error] [client 127.0.0.1] PHP Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed' in [no active file]:0\nStack trace:\n#0 {main}\n thrown in [no active file] on line 0 

,所以我想這個問題是該PHP的會話序列化不允許SimpleXMLElements。我將保存索引或其他內容。

+1

你調試過嗎?或者逐行刪除以獲得最小的原因? –

+1

當您下載xml文件並在本地訪問它時會發生什麼? –

+0

我不知道如何進入調試模式在PHP中,但原因是在最後一行,其中一個SimpleXMLElement被推送到一個數組。我可以將普通字符串推送到數組上,或者我自己定義的對象上,但是當試圖從$ catalog-CD數組中推送一個對象時,它會崩潰或發生什麼。 –

回答

2

插入的東西在上面你的程序是這樣的:

error_reporting(E_ALL); 
ini_set('error_log', 'phperror.log'); 
ini_set('log_errors_max_len', 0); 
ini_set('log_errors', true); 

,並期待在錯誤文件錯誤之後。

+0

+1 simple&bang on answer。 –

相關問題