title: How to share sessions data between Symfony controllers and classic stand alone php script where sessions are managed in memcache?
body: <p>I have a site built on Symfony framework and I had to add a legacy php script launched directly in the web directory.</p>
  
  <p>I also have to share session's data between the Symfony framework controllers and the stand-alone php script.</p>
  
  <p>Sessions on my server and the Symfony framework are configured to be in a memcached server (127.0.0.1 11211).</p>
  
  <p>Here are my Symfony config files :</p>
  
  <p>parameters.yml</p>
  
  <pre><code>session_memcached_host: 127.0.0.1
  session_memcached_port: 11211
  session_memcached_prefix: 'BPY_'
  session_memcached_expire: 3600
  </code></pre>
  
  <p>config.yml</p>
  
  <pre><code>imports:
      - { resource: session.yml }
  
      ...
  
      session:
          handler_id: session.handler.memcached
  </code></pre>
  
  <p>session.yml</p>
  
  <pre><code>services:
      session.memcached:
          class: Memcache
          arguments:
              persistent_id: %session_memcached_prefix%
          calls:
              - [ addServer, [ %session_memcached_host%, %session_memcached_port% ]]
  
      session.handler.memcached:
         class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler
         arguments: [@session.memcached, { prefix: %session_memcached_prefix%, expiretime: %session_memcached_expire% }]
  </code></pre>
  
  <p>Session in the Symfony controllers are set and read using :</p>
  
  <pre><code>$request-&gt;getSession-&gt;get('key');
  $request-&gt;getSession-&gt;set('key', $value);
  </code></pre>
  
  <p>In the stand-alone old php script, I use the global session array to set and get data. And in theory, to allow Symfony and my script share data I set and get data in :</p>
  
  <pre><code>$_SESSION['_sf2_attributes']
  </code></pre>
  
  <p>So, finally with this configuration, when I set data in the symfony controllers I do not see it in the stand-alone php script and when I set data in the php script I do not see it in the Symfony controllers.</p>
  
  <p>What is wrong in my configuration or my code?</p>