Eli : Memcached, MySQL, Highcharts

Solve PHP Warning : session_start() [function.session-start]: Node no longer exists

PHP Warning : session_start() [function.session-start]: Node no longer exists

This error is really annoying and can be hard to solve, it appears in two forms and only after a session has already been set.
This error will output two different messages :

PHP Warning:  Unknown: Node no longer exists in Unknown on line 0
PHP Warning : session_start() [function.session-start]: Node no longer exists in {session_start() file} on line 32

Solution is really simple, you have a SimpleXMLElement in your $_SESSION that does not deserialize properly.

Finding what variable trigger the error

PHP only tells you where the error kicks in (the session_start()), not where it really happened. To verify the diagnostic, first find your session.save_path

In PHP

[PHP]echo ini_get('session.save_path')

or simply

print_r($_SESSION)

On your server

php -i | grep session.save_path

Then go to this directory and open a sess_XXX file, then find a string looking like

myVariable|O:16:"SimpleXMLElement":0:{}

In serialized code, it means your variable myVariable is an Object, whose class name is 16 characters long and is SimpleXMLElement, 0:{} means it's empty.

Fixing the error

You need then to add a string cast in your PHP script for this variable when you assign it to the $_SESSION

# Invalid code
$_SESSION[myVariable] = $simpleXML->node->anotherNode->variable
# Correct code
$_SESSION[myVariable] = (string)$simpleXML->node->anotherNode->variable

If you have a more complex SimpleXMLElement (eg : a XML node, not just a string), then use the asXML() method

# Invalid Code
$_SESSION['myVariable'] = $simpleXML->node
# Accessing the variable
$myVariable = $_SESSION['myVariable'];
# Correct Code
$_SESSION[myVariable] = $simpleXML->node->asXML()
# Accessing the variable
$myVariable = new SimpleXMLElement($_SESSION['myVariable']);

Don't forget to change your access to this session variable as it will not be a SimpleXMLElement but rather a string containing XML.

Related Posts





comments powered by Disqus

You may also be interested in