0

We have an uploader which takes customer data, maps the data to our database structure and then uploads to the database. As part of the uploader, we load all the uploaded data into memory.

The issue we are having is that "large" datasets seem to cause session issues (current example failing is around 800kb). In the code base there is a check one every page load for the contents of the session to ensure the user is logged in and is valid etc - when performing this upload and things going awry, that check fails upon form submission. Through troubleshooting we discovered that when the issue occurs the session is emptied hence the check fails and causes the user to be logged out.

The code works fine with the 800kb dataset in development and also works fine on live with around 100kb dataset. This points to the code being OK and the issue being "environmental".

Session code is:

// If the session hasn't been started yet.
if (session_status() == PHP_SESSION_NONE)
{
    // Start the session.
    session_start();
}

and also then in the file itself:

$_SESSION['csv_data'] = array_map('str_getcsv', file($file_path));

and finally MUCH later (doesn't get here):

// Remove the session data.
unset($_SESSION['csv_data']);

We tried changing the memory_limit in PHP up to 1GB and even 10GB to no avail -likewise we upped max_filesize and post_max_size to 512MB respectively and same thing happens (we restarted both HTTPD and PHP-FPM)

Session configuration

The server is quad-core, 32GB RAM with 4 x 256GB SSD in RAID 10 - at no point does free memory drop below 28GB and both uptime and top show low usage so it doesn't seem to be lack of traditional resources causing an issue. It is running Centos 6.9 64 bit and Apache 2.4.9 with PHP 5.6.33

Is there anything else on the server which could be setting a limit to the (PHP) session/memory size? What else can we try to figure out what might be causing this?

bhttoan
  • 2,641
  • 5
  • 42
  • 71
  • How do you know session is emptied? How long does the upload process takes? – Itay Moav -Malimovka Feb 18 '18 at 01:55
  • Did you also change the `upload_max_filesize` and `post_max_size`? – M. Eriksson Feb 18 '18 at 02:01
  • 1
    Added some more information - user gets logged out and we found that is because the session is emptied – bhttoan Feb 18 '18 at 02:01
  • Yes both to 512M and still happens – bhttoan Feb 18 '18 at 02:04
  • What session driver are you using? – bishop Feb 18 '18 at 02:07
  • I believe it is native PHP but how can I check? – bhttoan Feb 18 '18 at 02:09
  • Post your entire [PHP session configuration](http://php.net/manual/en/session.configuration.php), as well as any [session related](http://php.net/manual/en/ref.session.php) code you are using. – bishop Feb 18 '18 at 02:20
  • Added session data – bhttoan Feb 18 '18 at 02:27
  • Try installing a sentinel value in your session, to see if that hangs around even after your `csv_data` goes away. For example, right after `session_start()`, add: `$_SESSION['sentinel'] = time();` – bishop Feb 18 '18 at 03:14
  • You're using `memcached`, which is designed for ["storing *small* chunks of data that are frequently accessed by the database and filesystem."](https://stackoverflow.com/a/13946349/2908724). Use a database or a filesystem session driver, or don't store so much data in the session. – bishop Feb 18 '18 at 03:20

0 Answers0