DEV Community

Cover image for Using Memcache for Session Storage in Legacy Symfony 1.4/1.5 Projects
Adam
Adam

Posted on • Edited on

Using Memcache for Session Storage in Legacy Symfony 1.4/1.5 Projects

Introduction

If you're maintaining a legacy Symfony 1.4/1.5 project and need to implement session storage with Memcache, this guide will help you get it up and running properly.

Prerequisites

  • Symfony 1.4/1.5 project
  • Docker environment
  • PHP 7.4 (recommended for legacy Symfony)
  • Memcached server

Step 1: Configure Your PHP Container

First, you'll need to install the Memcache extension in your PHP container:

# Install memcache extension (note: memcache, not memcached)
RUN apt-get update && apt-get install -y \
libmemcached-dev \
&& pecl install memcache-4.0.5.2 \
&& docker-php-ext-enable memcache

Note: We specifically use memcache-4.0.5.2 as it's compatible with PHP 7.4.

Step 3: Verify Your Setup

You can verify your Memcache session storage is working by connecting to your Memcached container and running some diagnostic commands:

`# Connect to your memcached container
docker exec -it your_memcached_container bash

Check general stats

echo "stats" | nc localhost 11211

Check session items

echo "stats items" | nc localhost 11211

View specific slab contents (replace X with slab ID from stats items)

echo "stats cachedump X 100" | nc localhost 11211`

Key Statistics to Watch

When checking your Memcache stats, pay attention to:

  • curr_items: Current number of items stored
  • get_hits/get_misses: Success rate of session retrievals
  • bytes: Memory usage
  • evictions: Should be 0 unless under memory pressure

Factories.yml

all:
  storage:
    class: sfCacheSessionStorage
    param:
      cache:
        class: sfMemcacheCache
        param:
          lifetime:  86400
          host:      memcached
          serializer:  IGBINARY
          mode:        compiled
          port:        11211
          persistent:  true
          session_name: HITC
          prefix:       hitc5_
          session_cookie_domain: .yourdomain.com

Enter fullscreen mode Exit fullscreen mode

Common Issues and Solutions

  1. Class Not Found Errors
    If you see Class 'sfMemcacheCache' not found, ensure:
    Memcache extension is properly installed
    Your cache is cleared (php symfony cc)

  2. Connection Issues
    If sessions aren't persisting, verify:
    Memcached host is correctly specified
    Port 11211 is accessible
    Persistent connections are enabled

  3. Performance Optimization
    For better performance:
    Use IGBINARY serializer
    Enable persistent connections
    Set appropriate prefix to avoid collisions
    Use compiled mode

Conclusion

Using Memcache for session storage in legacy Symfony projects can significantly improve performance and scalability. The configuration shown above provides a robust solution that works well with Symfony 1.4/1.5's architecture.

Remember to:

Use the correct Memcache extension version
Configure appropriate session lifetimes
Monitor memory usage
Set meaningful prefixes for multi-app environments

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (2)

Collapse
 
thepanz profile image
thePanz

Small information: PHP 8.x is also supported by the community-maintained fork of Symfony1 :)
And good progress has been made to support new caching systems (APCu included).
Give it a try!

Spoiler: I am one of the maintainers of the SF 1.5 fork at friendsofsymfony1/symfony1 :)

Collapse
 
adzhydra profile image
Adam • Edited

@thepanz Hey, thanks so much for jumping in with this info! Really cool to hear from someone who actually maintains the FriendsOfSymfony1 fork. I had no idea it supported PHP 8.x - that's super helpful to know!

For anyone still running older Symfony 1.x apps, definitely check out their fork (friendsofsymfony1/symfony1). It's awesome that the community is keeping these legacy apps alive and running on modern PHP versions.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay