PHP session locking and using Memcache to store sessions

I have a standard html page that has a few img tags, each of these are pointing to a php file on our server. When the php file is loaded, it saves some data to the session before then generating an image.

This data in the session from each of the scripts is then used in other script further in our application.

The php file to generate the image starts with session_start and when using the native PHP session handler all seems to work great. Each execution is done correctly and the full session data can be retrieved.

If I enable memcache to save the sessions then problems start to occur. It would appear that each of the PHP scripts are executed at the same time and thus when saving to the session only the last to execute actually stores any data.

After further investigation into Memcache I found that the latest stable version does not support session locking, and only in 3.0.4 do they introduce this - http://pecl.php.net/package/memcache/3.0.4

Is it safe to use 3.0.4 when it is only in beta?

Is there any alternative or a way around this issue in 2.2.7?

Please let me know if you would like to see examples of code.



the php-memcached extension supports session locking



the memcache and memcached extensions look syntactically similar so it may not be too much of a headache to give it a try. (memcached has a stable version 2.1.0 released 2012-08-07).


if you are set on using memcache 2.2.7 you will most likely have to implement the lock yourself by setting some "session_is_locked" variable in your session and then releasing/unsetting it when the script is done writing to the session. Then you'd always need to check if that variable is set before continuing with any scripts which write to the session.


  • Why am I getting invalid_grant for Google API calls from App Engine?
  • Multiple Servers And Memcached
  • How to get data from URL using Windows and C?
  • memcache won't store key/value because the value is too big
  • Issue with session.handler.native_file session handler in symfony2
  • Java Caching frameworks for maintaining huge data
  • PHP Post & Redirect with cURL Same As HTML Form [closed]
  • IP and domain create different session
  • Save and retrieve an image file in LibGDX
  • Sql indexes vs full table scan
  • jQuery and Uploadify session in the php file
  • setContentView() is not enough to switch between layouts?
  • SQL - Select lowest values with group by and order by?
  • Cypher - matching two different possible paths and return both
  • Android onKey w/ virtual keyboard
  • C#: Import/Export Settings into/from a File
  • Azure table store snapshot/backup capability
  • How to disable all widgets inside Panel or inside Composite?
  • Multicolored edittext hint
  • Security issues with PHP's Readfile method
  • Redux Form - Not able to type anything in input
  • How can I set a binding to a Combox in a UserControl?
  • Detect when Facebook like button is clicked
  • How can I sort a a table with VBA with given text condition?
  • AJAX Html Editor Extender upload image appearing blank
  • HTTP/2 streams vs HTTP/1.1 connections
  • print() is showing quotation marks in results
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Chrome doesn't support silverlight anymore? How to solve this?
  • Android fill_parent issue
  • All Classes Conforming to Protocol Inherit Default Implementation
  • formatting the colorbar ticklabels with SymLogNorm normalization in matplotlib
  • Get object from AWS S3 as a stream
  • Incrementing object id automatically JS constructor (static method and variable)
  • In LanguageTool, how do you create a dictionary and use it for spell checking?
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • How to load view controller without button in storyboard?