Session_Start Hangs

session_start hangs

There are many reasons for that, here are a few of them:

A. The session file could be opened exclusively.
When the file lock is not released properly for whatever reason, it is causing session_start() to hang infinitely on any future script executions.
Workaround: use session_set_save_handler() and make sure the write function uses fopen($file, 'w') instead of fopen($file, 'x')

B. Never use the following in your php.ini file (entropie file to "/dev/random"), this will cause your session_start() to hang:

<?php
ini_set("session.entropy_file", "/dev/random");
ini_set("session.entropy_length", "512");
?>

C.
session_start() needs a directory to write to.

You can get Apache plus PHP running in a normal user account. Apache will then of course have to listen to an other port than 80 (for instance, 8080).

Be sure to do the following things:
- create a temporary directory PREFIX/tmp
- put php.ini in PREFIX/lib
- edit php.ini and set session.save_path to the directory you just created

Otherwise, your scripts will seem to 'hang' on session_start().

session_start hangs

There are many reasons for that, here are a few of them:

A. The session file could be opened exclusively.
When the file lock is not released properly for whatever reason, it is causing session_start() to hang infinitely on any future script executions.
Workaround: use session_set_save_handler() and make sure the write function uses fopen($file, 'w') instead of fopen($file, 'x')

B. Never use the following in your php.ini file (entropie file to "/dev/random"), this will cause your session_start() to hang:

<?php
ini_set("session.entropy_file", "/dev/random");
ini_set("session.entropy_length", "512");
?>

C.
session_start() needs a directory to write to.

You can get Apache plus PHP running in a normal user account. Apache will then of course have to listen to an other port than 80 (for instance, 8080).

Be sure to do the following things:
- create a temporary directory PREFIX/tmp
- put php.ini in PREFIX/lib
- edit php.ini and set session.save_path to the directory you just created

Otherwise, your scripts will seem to 'hang' on session_start().

session_start() Hangs The Server

So, I'm guessing that it's an application layer problem because the other sites' sessions are working properly. However, this assumes that they have their sessions configured the same way - save yourself some time by double checking that your site isn't doing some "unique" in its configuration compared to the other sites.

I would next examine the other session related code that is running in your application. It could be that by calling session_start() you're putting your application into a state where it will run other code. For example, maybe there's a block of code that says "only run this function if this session variable is set" and by starting the session you're exposing that variable, where it wouldn't have been exposed and therefore not run the offending function if the session wasn't started.

Good luck.

PHP session_start(); has started hanging the server

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.

PHP session_start() causing HTTP requests to hang

Just a few ideas - in addition to pygorex's comment to first turn up the error_reporting, which should definitely come first.

  • Probably not it, but there are three hangups described in the User Contributed Notes to session_start:

    • When using /dev/random as session entropy file

    • When page is calling itself with the same session

    • On Windows

  • Can you read your session cookie and check whether a session file of that name exists in your /tmp directory? Is that file writable? Does it contain data?

  • If all else fails, the manual page on session_save_handler() has what seems like a full custom replacement for the default session handling functions. Consider using those for detailed debugging.

php7 session_start() times out page

In PHP7, The options parameter was added for session_start().

See more about session configuration.

In addition to the normal set of configuration directives, a read_and_close option may also be provided. If set to TRUE, this will result in the session being closed immediately after being read.

Perhaps the issue is related to the use_only_cookies variable that you can find in the Session's section of the php.ini file. Apache will crash if the use_only_cookies variable in the Session's section is set to 0 and everything is fine if it's set to 1.

You also checked that the use_strict_mode should be set to 1.



Related Topics



Leave a reply



Submit