Symfony Controller Action not updating entity when browser idle for an hour or more
<p><strong>Background:</strong><br>
We have a simple sign-in/sign-out application in our company Intranet that allows our employees to sign in and out of the office.</p>

<p><strong>Specs</strong>  </p>

<ul>
<li>Symfony 2.8</li>
<li>Doctrine ORM / MySQL</li>
<li>Server: Apache / Redis / Varnish</li>
<li>Browser: Issue is noticeable on Chrome, Safari, Firefox (we're a Mac shop)</li>
<li>Security: This uses the standard Symfony security model with bcrypt (Not using FOS or anything).</li>
<li>This site also uses CloudFlare</li>
</ul>

<p><strong>Use</strong><br>
When people sign out for lunch (for instance), they would submit a form that updates a status object (a one-to-one property of their user entity). This indicates to anyone using the intranet application that they are out to lunch and estimates a return time.  The user typically leaves this browser window up on their machine, and when they come back from lunch they click a check in button calling a controller action to reset the status entity properties, then performs a redirect back to the same page.</p>

<p><strong>The Problem</strong><br>
The application works great when you check-in / check-out for short periods of time (15 mins, 30 mins)... however if the browser sits idle for an hour or longer after checkout and the user clicks check in, the entity is not updated however the redirect does occur (without error). If you repeat the check-in immediately following that first failed attempt, it works.  The only time I can seem to get it to fail is when the browser has been idle for a time period of an hour or more.</p>

<p><strong>Where I've looked</strong>  </p>

<ul>
<li>I've scoured the logs and found no errors, warnings or notices that
appear related.</li>
<li>I've looked at the session information and cookies. Nothing seems out of the ordinary. The PHP Session shows an expiration of "Session", and all other cookies for the site, show expirations of more than 6 months.</li>
</ul>

<p><strong>Controller Update Action</strong><br>
The checkIn button is the one being clicked. See the conditional in this action for <code>checkIn</code>.</p>

<pre><code>public function updateAction(Request $request, $id, $view)
{
    $em = $this-&gt;getDoctrine()-&gt;getManager();
    $entity = $em-&gt;getRepository('IntranetStatusBundle:Status')-&gt;find($id);

    if (!$entity) {
        throw $this-&gt;createNotFoundException('Unable to find Status entity.');
    }

    $editForm = $this-&gt;createEditForm($entity, $view);
    $editForm-&gt;handleRequest($request);

    if ($editForm-&gt;isValid()) {
        if ($editForm-&gt;get('outToLunch')-&gt;isClicked()) {
            $outTime = date('g:i A');
            $inTime = strtotime($outTime) + 60*60;
            $checkInTime = date('g:i A', $inTime);
            $entity-&gt;setState('Out');
            $entity-&gt;setLocation('Lunch');
            $entity-&gt;setTimeOut($outTime);
            $entity-&gt;setTimeIn($checkInTime);
            $entity-&gt;setStatusNotes(null);
        }
        if (($editForm-&gt;has('checkIn') &amp;&amp; $editForm-&gt;get('checkIn')-&gt;isClicked()) || $entity-&gt;getState() == "In") {
            $entity-&gt;setState('In');
            $entity-&gt;setLocation('');
            $entity-&gt;setTimeOut(null);
            $entity-&gt;setTimeIn(null);
            $entity-&gt;setStatusNotes(null);
        }
        if ($entity-&gt;getState() == 'Out' &amp;&amp; $entity-&gt;getTimeOut() == null) {
            $entity-&gt;setTimeOut(date('m-d-Y g:i A'));
        }
        if ($entity-&gt;getState() == 'Out' &amp;&amp; $entity-&gt;getTimeIn() == null) {
            $entity-&gt;setTimeIn(date('???'));
        }
        $em-&gt;flush();
    }

    return $this-&gt;redirect($this-&gt;generateUrl('status',array('view'=&gt;$view)));

}
</code></pre>

<p><strong>security.yml</strong></p>

<pre><code>security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext
        Intranet\UserBundle\Entity\User:
            algorithm: bcrypt
    role_hierarchy:
        ROLE_DEV:           ROLE_USER
        ROLE_ADMIN:         ROLE_USER, ROLE_DEV
        ROLE_SUPER_ADMIN:   [ROLE_USER, ROLE_DEV, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        administrators:
            entity: { class: IntranetUserBundle:User }
    firewalls:
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false
            switch_user: true
        secured_area:
            switch_user: true
            pattern:   ^/
            anonymous: ~
            form_login:
                login_path: login
                check_path: login_check
                csrf_provider: security.csrf.token_manager
                require_previous_session: false
            logout:
                path:   logout
                target: login
            remember_me:
                key:      "%secret%"
                lifetime: 31536000 # 365 days in seconds
                path:     /
                domain:   ~ # Defaults to the current domain from $_SERVER
    access_control:
       - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
       - { path: ^/intranet, roles: ROLE_USER }
       - { path: ^/inout, roles: ROLE_USER }
</code></pre>

<p>Thank you for looking, and if there's more code I can provide to assist, please let me know in the comments.</p>