Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can be the maximum size for the $_SESSION?

I am importing a csv file with more then 5,000 records in it. What i am currently doing is, getting all file content as an array and saving them to the database one by one. But in case of script failure, the whole process will run again and if i start checking the them again one by one form database it will use lots of queries, so i thought to keep the imported values in session temporarily.

Is it good practice to keep that much of records in the session. Or is there any other way to do this ?

Thank you.

like image 421
Chetan Sharma Avatar asked Jan 22 '23 19:01

Chetan Sharma


1 Answers

If you have to do this task in stages (and there's a couple of suggestions here to improve the way you do things in a single pass), don't hold the csv file in $_SESSION... that's pointless overhead, because you already have the csv file on disk anyway, and it's just adding a lot of serialization/unserialization overhead to the process as the session data is written.

You're processing the CSV records one at a time, so keep a count of how many you've successfully processed in $_SESSION. If the script times out or barfs, then restart and read how many you've already processed so you know where in the file to restart.

like image 181
Mark Baker Avatar answered Jan 25 '23 23:01

Mark Baker