Session Problems with OS X

Hello,

I recently set up the yii environment on Os x using MAMP.

I copied my test application over from a linux box, where it worked fine.  When I run it from osx, i received a session error when printing contents from an array. 

session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /Users/remo/html/robohive/protected/controllers/SiteController.php:105)





Source File





/Users/remo/html/yii/framework/web/CHttpSession.php(102)





00090:         return false;


00091:     }


00092: 


00093:     /**


00094:      * Starts the session if it has not started yet.


00095:      */


00096:     public function open()


00097:     {


00098:         if(session_id()==='')


00099:         {


00100:             if($this->getUseCustomStorage())


00101:                 session_set_save_handler(array($this,'openSession'),array($this,'closeSession'),array($this,'readSession'),array($this,'writeSession'),array($this,'destroySession'),array($this,'gcSession'));


00102:             session_start();


00103:         }


00104:     }


00105: 


00106:     /**


00107:      * Ends the current session and store session data.


00108:      */


00109:     public function close()


00110:     {


00111:         if(session_id()!=='')


00112:             @session_write_close();


00113:     }


00114: 


Stack Trace





#0 /Users/remo/html/yii/framework/web/CHttpSession.php(102): session_start()


#1 /Users/remo/html/yii/framework/web/CHttpSession.php(75): CHttpSession->open()


#2 /Users/remo/html/yii/framework/base/CApplication.php(710): CHttpSession->init()


#3 /Users/remo/html/yii/framework/web/CWebApplication.php(233): CWebApplication->getComponent()


#4 /Users/remo/html/yii/framework/web/auth/CWebUser.php(83): CWebApplication->getSession()


#5 /Users/remo/html/yii/framework/base/CApplication.php(710): CWebUser->init()


#6 /Users/remo/html/yii/framework/base/CApplication.php(132): CWebApplication->getComponent()


#7 /Users/remo/html/robohive/protected/views/layouts/main.php(25): CWebApplication->__get()


#8 /Users/remo/html/yii/framework/web/CBaseController.php(119): require()


#9 /Users/remo/html/yii/framework/web/CBaseController.php(88): SiteController->renderInternal()


#10 /Users/remo/html/yii/framework/web/CController.php(427): SiteController->renderFile()


#11 /Users/remo/html/robohive/protected/controllers/SiteController.php(109): SiteController->render()


#12 /Users/remo/html/yii/framework/web/actions/CInlineAction.php(32): SiteController->actionSearch()


#13 /Users/remo/html/yii/framework/web/CController.php(218): CInlineAction->run()


#14 /Users/remo/html/yii/framework/web/CController.php(203): SiteController->runAction()


#15 /Users/remo/html/yii/framework/web/CController.php(178): SiteController->runActionWithFilters()


#16 /Users/remo/html/yii/framework/web/CWebApplication.php(149): SiteController->run()


#17 /Users/remo/html/yii/framework/web/CWebApplication.php(121): CWebApplication->runController()


#18 /Users/remo/html/yii/framework/base/CApplication.php(146): CWebApplication->processRequest()


#19 /Users/remo/html/robohive/index.php(11): CWebApplication->run()

Would this be something related to how sessions are set up in apache/php conf on osx or something different.  Can anyone point me in the right direction?

Thanks,

R

Check line 105 in your SiteController.php ?

Thank you for your reply Qiang.

I checked 105 and tried to narrow it down by commenting out most of the code.  It seems to be related to the echo "test" line. Not sure what I'm doing wrong.  The code seems fine. The echo test statement does print "test" to the screen and then the error immediately follows.

public function actionSearch()


	{


		//lets first see if "match" data from db is cached.  If so, fine.


		//If not, let's load up cache from "match" table.


			


			


			


			


			


		$search=new SearchForm;


		if(Yii::app()->request->isPostRequest)


		{


			// collect user input data


			if(isset($_POST['SearchForm']))


			$search->setAttributes($_POST['SearchForm']);


			// validate user input and redirect to previous page if valid


			if($search->validate())


			{


				//$this->redirect(Yii::app()->user->returnUrl);


				//print_r($search->parseWords("hello how are you"));


				//$phrase=$search->what; //get what the user types into the "what" field


				//$remo=$search->parseWords($phrase);  //parse the words


				//$remo=$search->removeStopWords($remo); //remove stop words


				//$remo=$search->cleanWords($remo); //clean up stem words


				//foreach ($remo as $key) {echo ("the answer is: $key<br/>");}


				echo "test";


			}


		}


		// display the login form


		$this->render('search',array('search'=>$search));


	}

I guess your view contains reference to Yii::app()->user, which will open the session (and send out header). Your echo statement before that will then cause the problem.

Thanks Qiang. 

I think this is something related to MAMP because it works fine running on Linux.  I did some searching on google and their seems to be  similar problems related to spaces or carriage returns in the configuration files.  No idea where to look, but I guess I'll have to figure it out. 

Thanks for your help.

R

Seems like I had output_buffering turned off in php.ini. 

Regards,

R