开发者

PHP Session_start is hanging

Kind of a weird issue, ok here is my setup...

  1. domain.com calls reads from an Iframe on sub.domain.com
  2. sub.domain.com makes an ajax call to sub.domain.com/call.php
  3. sub.domain.com returns ajax call to domain.com

AKA long-polling

Now, everything works perfectly when there is no session data (I close the browser and restart the page). However, once I reload the page and their is session data, call.php does a start_session() and hangs there.

I have tried almost everything and can't figure this out. I've tried destroying the session, unsetting all the session variables, modifying some ini settings, and nothing has worked.

开发者_StackOverflow

Here is the code of call.php where the session data is...

session_start();

        $sql = ("SELECT userid FROM status WHERE typing = '".mysql_real_escape_string($userid)."'");
        $result = mysql_query($sql);

        if ($result && mysql_num_rows($result) > 0) {
            $row = mysql_fetch_array($result);
            $typing_id = $row['userid'];
            if (!empty($typing_id)) {
                if (isset($_SESSION['typing2'])) {
                    unset($_SESSION['typing2']);
                }
            } else {
                $typing_id = "-1";
            }
        } else {
            $typing_id = "-1";
            if (isset($_SESSION['typing'])) {
                unset($_SESSION['typing']);
            }
        }

        if ($_SESSION['typing'] != $typing_id && !isset($_SESSION['typing2']) || $initialize == "1") {
            $typing = array('typing_id' => $typing_id);
        }

        if ($typing_id == "-1") {
            $_SESSION['typing2'] = "-1";
        } else {
            $_SESSION['typing'] = $typing_id;
        }

Does anyone have any ideas? I was thinking it might have to do with the domain but I'm not sure.

Thanks!


I actually found out (after hours and hours of debugging and research) that the problem is being caused because the PHP session locks up. Then, when the new page loads, it won't work until the old session times out. A session_write_close() will fix it.


default session storage in php is cookie based. if you are using that you must set domain for your session cookie in php.ini

http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-domain

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜