0

Running this on my local wamp server gives me ERR_CONNECTION_RESET when trying to access the .php file through a browser. Whats going on here?

<?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]);
?>

here is a piece of the output of 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 => [...]

EDIT: Found this from looking in the apache log as suggested:

[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

So i guess the problem is that php's session serialization doesnt allow SimpleXMLElements. I'll save an index or something instead.

7
  • 1
    Have you debugged it? Or eliminated line-by-line to get the minimal cause? Commented Apr 2, 2013 at 7:30
  • 1
    What happens when you download the xml file and access it locally? Commented Apr 2, 2013 at 7:32
  • i dont know how to go into debug mode in php, but the cause is in the last line, where a SimpleXMLElement is pushed to an array. I can push a normal string onto the array, or an object i defined myself, but when try to push an object from the $catalog-CD array, it crashes or something. Commented Apr 2, 2013 at 7:34
  • serverfault.com/questions/74313/… Commented Apr 2, 2013 at 7:34
  • same thing happens when i access the xml file locally Commented Apr 2, 2013 at 7:35

1 Answer 1

3

Insert something on top your program like this:

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

and look at error file after error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.