Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7026043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:03:54+00:00 2026-05-28T00:03:54+00:00

EDIT I tried debugging this with xdebug and netbeans. It’s weird that the exports

  • 0

EDIT
I tried debugging this with xdebug and netbeans. It’s weird that the exports will work during the debug session if I put in some breakpoints. However, with no break points, a more realistic environment, the exports don’t work.

I’ve tried adding sleeps into some parts of the code.

I think that maybe PHP is ending before the Redis commit is completed. Maybe the Redis connections are being done asynchronously, but I checked PRedis and the default is a synchronous connection.


I am working on a reporting tool.

Here is the basic issue.

We store a report into the session object but on later requests when we try to get to the report in the session object it’s gone.

Here is a more detailed version.

I store a ‘report’ object into the session like so

  $_SESSION['report_name_unixtimestamp'] = gzcompress( serialize( $reportObject ) );

The user sees the report in some table form and then if they want they can export it. The report could change so the idea behind storing it in the session like this is that when the user exports it to PDF, Excel, etc, they’ll be getting a report identical to the one they are viewing.

The user clicks on an export button and on the PHP side it will go into the session, fetch the report via the key provided as a get parameter (uncompresses and unserializes it), create the export and send it to the user for download.

This has worked well up until the point that we tried to introduce the Redis caching server as a tool for better session management.

What happens now is the following:

The first time we run the report it will get stored into the cache and the export will work successfully.

We will run the report again, with the same user account in the same session. This changes the unixtimestamp and so there should be two entries in the $_SESSION. ( $_SESSION['report_name_oldertimetamp'] and $_SESSION['report_name_newertimestamp'] ). When we click on the export button again we get an error saying that the file doesn’t exist ( because it hasn’t been sent by the server ).

If we check the redis server for the newer version of the report it isn’t there, but the old timestamp is still there.

Now, this worked with the file session management but not with Redis. we’ve tried the redis module for php as well as the pure php client Predis.

Does anyone have any ideas?

Here are a few more details :

  1. Redis has NOT run out of memory. We’ve checked this many times.
  2. We already know that to unserialize the report object in the session the report class has to be included already. ( remember, the first export works fine but anything after that fails )
  3. If we check the php session object during the request that the report is running on, it WILL contain the newer report but it never makes it to Redis.

Below is the save handler that is being used with Predis.
The redis_session_init is the function I call right before session_start() so that it gets registered. I’m not sure how the redis_session_write function works though so maybe someone can help me with that.

    <?php
    namespace RedisSession
    {

        $redisTargetPrefix = "PHPREDIS_SESSION:";
        $unpackItems = array( );
        $redisServer = "tcp://cache.emcweb.com";

        function redis_session_init( $unpack = null, $server = null, $prefix = null )
        {
            global $unpackItems, $redisServer, $redisTargetPrefix;

            if( $unpack !== null )
            {
                $unpackItems = $unpack;
            }

            if( $server !== null )
            {
                $redisServer = $server;
            }

            if( $prefix !== null )
            {
                $redisTargetPrefix = $prefix;
            }

            session_set_save_handler( 'RedisSession\redis_session_open', 'RedisSession\redis_session_close', 'RedisSession\redis_session_read', 'RedisSession\redis_session_write', 'RedisSession\redis_session_destroy', 'RedisSession\redis_session_gc' );
        }

        function redis_session_read( $id )
        {
            global $redisServer, $redisTargetPrefix;

            $redisConnection = new \Predis\Client( $redisServer );
            return base64_decode( $redisConnection->get( $redisTargetPrefix . $id ) );
        }

        function redis_session_write( $id, $data )
        {
            global $unpackItems, $redisServer, $redisTargetPrefix;

            $redisConnection = new \Predis\Client( $redisServer );
            $ttl = ini_get( "session.gc_maxlifetime" );

            $redisConnection->pipeline( function ($r) use (&$id, &$data, &$redisTargetPrefix, &$ttl, &$unpackItems)
        {
            $r->setex( $redisTargetPrefix . $id, $ttl, base64_encode( $data ) );

            foreach( $unpackItems as $item )
            {
                $keyname = $redisTargetPrefix . $id . ":" . $item;

                if( isset( $_SESSION[ $item ] ) )
                {
                    $r->setex( $keyname, $ttl, $_SESSION[ $item ] );
                }
                else
                {
                    $r->del( $keyname );
                }
            }
        } );
        }

        function redis_session_destroy( $id )
        {
            global $redisServer, $redisTargetPrefix;

            $redisConnection = new \Predis\Client( $redisServer );
            $redisConnection->del( $redisTargetPrefix . $id );

            $unpacked = $redisConnection->keys( $redisTargetPrefix . $id . ":*" );

            foreach( $unpacked as $unp )
            {
                $redisConnection->del( $unp );
            }
        }

        // These functions are all noops for various reasons... opening has no practical meaning in
        // terms of non-shared Redis connections, the same for closing. Garbage collection is handled by
        // Redis anyway.
        function redis_session_open( $path, $name )
        {

        }

        function redis_session_close()
        {

        }

        function redis_session_gc( $age )
        {



        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:03:54+00:00Added an answer on May 28, 2026 at 12:03 am

    The issue was solved and it was much dumber than I thought.

    The save handler doesn’t implement locking in any way. On the report pages there are multiple requests being made to the server via ajax and the like. One of the ajax requests starts before the report gets saved to session space. Thus, it reads the session, then writes the session at the end.

    Since the reports executes faster every time, the report would get cached to the session in Redis but would then be overwritten by the other script that had an older version of the sessien.

    I had help from one of my co-workers. Ugh! This was a headache I’m glad to be over.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: Of course my real code doesn't look exactly like this. I tried to
I tried the following: $.load(Views/chatBox.html).appendTo('body') Console Output: TypeError: $.load is not a function EDIT
Does anyone know how can I edit a subitem on a listView? I've tried
Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: From another question I provided an answer that has links to a lot
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business
EDIT: This question is more about language engineering than C++ itself. I used C++
OK, this is impossible, but I will try to explain the situation here. Let's
Current code: short s; s = short.Parse(this.txtFields3.Text); I've gone through with debugging, and can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.