Caching and tmp partition exhaustion

Topics: User Forum
Feb 11, 2011 at 8:22 PM

Got this from my host:

It appears that you've had multiple (PHPExcel.98444d54d0670c2370.23896367.cache) files inside your [/tmp] directory. These files were 134MB each and quickly filled up your [/tmp] directory. We can increase the size of your [/tmp] partition, however first we wanted to ensure that any code you might be running using PHPExcel is not incorrectly configured causing such large cache files. If there is something configured incorrectly raising the [/tmp] partitions usable disk-space could lead to further issues of that just filling up as well.

Please review your usage of PHPExcel in your scripts and let us know if you expect these large cache files to consistently fill up your [/tmp] partition.

Here is the code I use in my scripts:

    set_include_path(get_include_path() . PATH_SEPARATOR . 'PHPExcel/Classes/'); 
    require_once 'PHPExcel/Classes/PHPExcel.php';
    require_once 'PHPExcel/Classes/PHPExcel/IOFactory.php';
    $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_discISAM;
    PHPExcel_Settings::setCacheStorageMethod($cacheMethod);
    $objReader = PHPExcel_IOFactory::createReaderForFile($file);
    $objReader->setReadDataOnly(true);
    $objPHPExcel  = $objReader->load($file);
    $objWorksheet = $objPHPExcel->getActiveSheet();


What am I doing wrong to make this happen?

Also what *is* the best caching method to use because I have several users that need to import large, 2MB+, spreadsheets.

Feb 11, 2011 at 9:00 PM

How can I set the directory where the cache files are stored? Right now hey are not in the actual /var/tmp, which is my actual tmp directory but it /tmp which is symbolic for /usr/tmpDSK.

I've disabled Excel imports, they'll have to be done manually by conversion to tab-delimited, until I can get this worked out.

Coordinator
Feb 11, 2011 at 9:23 PM

DiskISAM uses the temporary directory identified by a call to sys_get_temp_dir(). There is currently no method to set the temporary directory manually.

There are a few issues with this PHP function, that was only introduced in PHP 5.2.1, especially if PHP is being run with the suhosin patch.

To get round these issues, we do have a customised version of the function in the PHPExcel_Shared_File class. I've modified the DiskISAM class to use this customised version rather than the standard sys_get_temp_dir(). Hopefully this will resolve your problem.

Coordinator
Feb 11, 2011 at 9:24 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Feb 11, 2011 at 9:38 PM
mrbaseball34 wrote:

Also what *is* the best caching method to use because I have several users that need to import large, 2MB+, spreadsheets.

That's not something that I can tell you, because it's totally dependent on your environment: for example, WinCache is very efficient, but requires you to be running on a Windows/IIS server, with WinCache enabled. Nor does everybody have APC or memcache enabled, and these also have limitations on the amount of memory available, but they are also good for reducing the memory used by large workbooks (though I find memcache too slow on my servers... others may not have that problem). For my production environments, PHPTemp is the best method for me (with a 256MB base memory), but I have complete control of my production servers, and lots of memory. On the development box where I'm typing this, APC is the best.

Each method has its own advantages and drawbacks, and each trades off memory against speed in different proportions. If you run from the CLI, and speed isn't critical to your application, then diskISAM is a reasonable choice. Running from Apache, APC or memcache might be better.

I don't know your server circumstances, or the requirements of your applications/users; so I can't advise you which method is best for you. That's why I provide the range of different methods, so that you can make your own choice.

Feb 12, 2011 at 4:51 PM
Edited Feb 12, 2011 at 4:52 PM

If there are large files being created in that directory, then why is there not GC cleaning them up after they are done? Or how about reusing the files so there are not so many?

That would be the best way to handle this.

Coordinator
Feb 12, 2011 at 5:06 PM
Mrbaseball34 wrote:

If there are large files being created in that directory, then why is there not GC cleaning them up after they are done? Or how about reusing the files so there are not so many?

That would be the best way to handle this.


I don't know why not, permissions perhaps. The logic in the code should clean up all cache files that are created: this is defined in the destructor for the PHPExcel_CachedObjectStorage_DiscISAM class.