Zend Framework

Zend_Session setId doesn't work right from PHP CLI

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Not an Issue
  • Affects Version/s: 1.0.0
  • Fix Version/s: Next Major Release
  • Component/s: Zend_Session
  • Labels:
    None
  • Fix Version Priority:
    Should Have

Description

If you try to use Zend_Session setId to restablish a session inside of a PHP CLI script, you get hit by one or two errors:

The session has already been started. The session id must be set first.

Also if your script happens to output anything to the screen:

You must call Zend_Session::setId() before any output has been sent to the browser; output started in

(This shouldn't matter because you're using a CLI so headers has no bearing on anything. There should be a way to override this check)

The code I am using is as simple as:

Zend_Session::setId($input['TOKEN']);
Zend_Session::start();

It makes no difference if I call Zend_Session::destroy() prior to this. The code above works fine from CLI using Zend_XMLRpc, but it won't work if I call the functions directly from my own CLI script.

Activity

Hide
Michael Long added a comment -

Although I don't know all the ramifications, etc., but one easy solution I might suggest is to add an IF statement around the first two checks, like this:

if (php_sapi_name() != 'cli')
{
if (defined('SID')) { throw new Zend_Session_Exception('The session has already been started. The session id must be set first.'); }

if (headers_sent($filename, $linenum)) {
throw new Zend_Session_Exception("You must call "._CLASS.'::'.FUNCTION_.
"() before any output has been sent to the browser; output started in {$filename}/{$linenum}");
}
}

Show
Michael Long added a comment - Although I don't know all the ramifications, etc., but one easy solution I might suggest is to add an IF statement around the first two checks, like this: if (php_sapi_name() != 'cli') { if (defined('SID')) { throw new Zend_Session_Exception('The session has already been started. The session id must be set first.'); } if (headers_sent($filename, $linenum)) { throw new Zend_Session_Exception("You must call "._CLASS.'::'.FUNCTION_. "() before any output has been sent to the browser; output started in {$filename}/{$linenum}"); } }
Hide
Wil Sinclair added a comment -

This issue should have been fixed for the 1.5 release.

Show
Wil Sinclair added a comment - This issue should have been fixed for the 1.5 release.
Hide
Wil Sinclair added a comment -

This doesn't appear to have been fixed in 1.5.0. Please update if this is not correct.

Show
Wil Sinclair added a comment - This doesn't appear to have been fixed in 1.5.0. Please update if this is not correct.
Hide
Ralph Schindler added a comment -

Zend_Session (currently) is not supported in the CLI environment. This is in part due to the fact that php's ext/session is unpredictable in the CLI env.

Scheduling for 2.0 to evaluate.

Updating project management info.

Show
Ralph Schindler added a comment - Zend_Session (currently) is not supported in the CLI environment. This is in part due to the fact that php's ext/session is unpredictable in the CLI env. Scheduling for 2.0 to evaluate. Updating project management info.
Hide
Ralph Schindler added a comment -

Unsupported use case, if you think this should be a supported use case, please add comments here:

http://framework.zend.com/wiki/display/ZFDEV/Zend_Session+2.0

Show
Ralph Schindler added a comment - Unsupported use case, if you think this should be a supported use case, please add comments here: http://framework.zend.com/wiki/display/ZFDEV/Zend_Session+2.0

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
1d
Original Estimate - 1 day
Remaining:
1d
Remaining Estimate - 1 day
Logged:
Not Specified
Time Spent - Not Specified