store worksheet with apc and fetch gives non-object error

Topics: User Forum
Jul 14, 2010 at 10:39 PM
Edited Jul 15, 2010 at 12:11 PM

PHP Version 5.2.6-3ubuntu

4.5 PHPExcel 1.7.3c

OS Ubuntu 9.04 APC 3.0.19

Hello, The following below steps work (have a series of steps and don't want to reload the file for each step)

$objReader = PHPExcel_IOFactory::createReader($fileFormat);
$objFile = $objReader->load($fileName);
$objWorksheet = $objFile->getActiveSheet();
$sheetName = $objWorksheet->getTitle();
apc_store(session_id(), $objWorksheet); 

and to retrieve:

$objWorksheet = apc_fetch(session_id());

I get the member function on a non-object error when the file is large e.g. 5,000 - 10,000 rows.

I was hoping someone might be able to suggest the correct apc settings in the php.ini file I need to tweak to get a 10,000 file to pass.

Currently I use defaults except below:


apc.enabled = 1

apc.max_file_size = 10M

apc.shm_segments = 1

apc.shm_size = 64

apc.stat = 1


A 10,000 row file is taking about 9 - 11 seconds to load if I need to change ttl settings.

Any other insights to php apc with PHPExcel would be welcomed - very much a php apc novice.

Many thanks to the developers for a great product.

Jul 20, 2010 at 9:02 PM

It isn't a good idea storing a PHPExcel object in APC.

Storing an object in APC requires that the object be serialised... a function performed automatically by APC. However, a PHPExcel object comprises a series of nested objects that contain cyclic references (e.g. a worksheet object references cell objects, and the cell objects reference their parent worksheet). This cyclic relationship causes problems in PHP when the objects are unserialized (when read from APC) because the unserialize function creates a new parent object for every child object rather than linking correctly to a single parent object.