1
votes

I have an Excel file (about 5000 to 8000 rows & 32 cols) that would be edited with values from a table. I have succesfully done this but I want to reduce the scripts average run time.

So i tried saving the loaded object to the session and checking if it exist every time the script runs instead of reloading every time.

if (!isset($_SESSION['col10Read']))
{
    global $sheet;
    $objPHPExcel = $objReader->load($inputFileName);
    $_SESSION['col10Read'] = $objPHPExcel;
    $sheet = $objPHPExcel->getActiveSheet();
}
else
{
    global $sheet;
    $sheet = $_SESSION['col10Read']->getActiveSheet();
}

but when i run the code after the first time (when my session variable exist), I get this error:

Fatal error: Uncaught exception 'PHPExcel_Exception' with message 'Your requested sheet index: 0 is out of bounds. The actual number of sheets is 0.'

I've been trying diff ways for a day now, searched Google endlessly, any help would apprieciated.

1
Putting the object inside a session is not going to make anything faster - user557846
That's a very large object to go placing in the $_SESSION variable. If PHP is using a tmp folder for its session data, there's a good chance you run out of disk space! - Ben Hillier
@BenHillier I thought of all these issues so i load only one column now thus the size of the object is about 40mb, is that still too large. - Peter Esenwa
@UchennaPeterEsenwa It can depend on the size of the temp folder. Are you in linux? The command df -h should shed some light. It could of course be another problem entirely ;-) - Ben Hillier
@BenHillier I use Windows, but i think disk space wouldn't be an issue. - Peter Esenwa

1 Answers

1
votes

$_SESSION works by serializing any objects that are passed to it. Not all classes are designed to be serialized, and it looks like the type of object you're storing is among those. The easiest way to go about solving such problems is to store enough information to restore the state of the object without storing the object itself: for example, you could store the filename and the row that you were on. I recognize that this is probably what you were trying to avoid, but unfortunately, the framework you're using wasn't designed for the optimizations you're looking to implement.