Why does this PHP script (called by AJAX) randomly not load SESSION correctly? Why does this PHP script (called by AJAX) randomly not load SESSION correctly? ajax ajax

Why does this PHP script (called by AJAX) randomly not load SESSION correctly?


Two things can cause this issue.

  1. You don't have enough space in session save path (df -h) or you server don't have permission to save it.
  2. Your server is behind a load balancer, and you must save sessions in a persistent backend like memcache or redis.


If you're running a load balancer then you have to make sure your servers are hitting a common point for data. By default PHP stores sessions in the local file system. That becomes a problem if your load balancer sends you from server A to server B, where that file doesn't exist. You could set up a network share and make sure all web servers use that share. So you could create an NFS share and then add session_save_path or set it within php.ini

session_save_path('/your/nfs/share/here');

Another option is to write your own session handler that puts sessions into your database. You could then use something like memcached to store the sessions in a way that you won't hammer your DB every time you read your session data.


The screenshot I have attached is same for almost all 25-30 runs I have run. [1]: http://i.stack.imgur.com/MgLpS.jpg Check your session data size maybe it's exceeding the cache size. or some other session data is being stored exhausting your cache memory. Increase your cache size maybe it will help for your scenario.