Вопрос

I have a DMZ set up with a web server and an application server, both running Ubuntu under gnome (v11.04 on the web server and v11.10 on the application server). session_start() has started hanging on the application server. The code is located on the application server and it does not hang when I access my web site and access the page with the session_start() call on it. It seems that every session_start() has started hanging on the application server although I have no problems with the associated pages when I access them from other computers or across the web. Also I have only just started having this problem on the application server without having made any changes to my php code. Could it be that some buffer has filled up and needs to be cleared?

I tried editing /etc/php5/apache2/php.ini and setting

session.save_path = "/tmp"

/tmp exists.

But I still have the problem. I can stop it hanging by preceding session_start() with session_end() but then it does not execute the remaining PHP or html code in the file.

/var/log/apache2/error.log included the following message:

PHP Notice:  A session had already been started - ignoring session_start() in
/var/www/DraculaPgm.php on line 101, referer: 
http://MyWebSite.com/ApplicationServer/Dracula.php

Any assistance with this would be greatly appreciated,
Peter.

Update 29-Dec-2012

Thank you to everyone who replied to this question. Unfortunately, I tried all of the suggestions and 'session_start()' still hangs. However, if I leave it for a few minutes, it breaks with the following error message.

Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /ApplicationServer/Dracula.php.

Reason: Error reading from remote server

Apache/2.2.17 (Ubuntu) Server at MyWebSite.com Port 80

I have squid installed on the web server. Could this be a problem?

Thanks,
Peter

Это было полезно?

Решение 2

I changed 'session_start()' to the following block.

if(!isset($_SESSION))
{
    session_destroy();
    session_start();
}

I now do not have the problem. I am hesitant to say that it fixed the problem since it did not seem to fix it right away.

Thank you to everyone for your help,
Peter.

Другие советы

This sounds like a configuration issue. Make sure that PHP is reporting all errors, i.e., error_reporting(E_ALL) and either display or log all errors. (You might even want to enable display_startup_errors in your php.ini) - reporting all errors may shed light on what's going on. (if you need help you can post any errors that you get from this as an edit) You may want to look at the following as well for troubleshooting the issues with sessions:

Alternatively if none of those show anything you may want to read over the bug report at https://bugs.php.net/bug.php?id=28856&edit=1 depending on what version of PHP you are running.

Try changing the permission of the /tmp folder by doing chmod 777 /tmp and check if its working.If its working then change the permission mode to make it more secure

Try checking out this Question I call session_start() the script hangs and nothing happens

And this http://www.projectpier.org/node/1934

"It seems that the session file is opened exclusively. On some occasions (Windows) I have found that the file lock is not released properly for whatever reason, therefore causing session_start() to hang infinitely on any future script executions. My way round this problem was to use session_set_save_handler() and make sure the write function used fopen($file, 'w') instead of fopen($file, 'x')"

You can find many others having the same problem and their workarounds if you go through http://php.net/manual/en/function.session-start.php

if(!isset($_SESSION)) 
{ 
    session_start(); 
}

Use this at the top of your PHP file!

And for your info: session_destroy() is used to end session.

Before anything else - try another browser!

I just encountered this session_start problem. I checked my tmp folder and everything and I was about to call my hosting-provider until I thought I should try another browser first because it might have to do with session cookies.

I work with chrome, so I tested in IE and found that it was indeed the case: It worked in another browser!

I closed IE ;) - went back to chrome, looked for the cookie (PHP_SESS_ID), deleted it and everything works again!

Well, the good part is - Just like you guys I got to brush up my knowledge of -jay- sessions! ;)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top