1

I am using a PHP library PHPExcel in my script. Now the library is very large nearly around 7MB and I dont think I am using all the features of it. I wish to make my script lightweightby delting the files in PHPExcel which I am not using.

How to achieve this?

1 Answer 1

4

PHPExcel uses an autoloader that only includes the files that your script actually uses, so the actual "in memory" size of the script is kept to a minimum.

If you're not using any language other than English, then you can delete all the subdirectories in Classes/PHPExcel/locale... if you want another locale such as French, then you can delete all subdirectories except fr (saving about 0.5MB).

However, I wouldn't recommend deleting anything else... especially without knowing exactly what you need.

If disk space is absolutely critical, and you're only working with (for example) xls files, then you could delete all the other readers and writers (note that the PDF writer uses the HTML writer); but you must then explicitly identify which reader or writer you're going to use when reading rather than relying on the IOFactory's autodetect: so explicit syntax:

$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = $objReader->load("excel5File.xls");

should be used instead of

$objPHPExcel = PHPExcel_IOFactory::load("excel5File.xls");

If you don't need the PDF writer, then deleting Classes/PHPExcel/Shared/PDF (tcpdf) will save about 4.5MB of disk

However, I'd be reluctant to make any guarantees that you wouldn't run into problems somewhere.

If you really need to shrink the size on disk, then stripping out comments from the code is going to reduce the size quite drastically... I'm sure there are scripts available that will do this.

EDIT

Paul Dixon's response to this question on stripping comments from a script might help minify to code on disk.

Sign up to request clarification or add additional context in comments.

5 Comments

@Daniel have a look at the credits of PHPExcel or look into Mark's profile, then you will understand why ;)
@Daniel: He is the author of PHPExcel :)
@Daniel - Insider knowledge :-)
@Gordon, @sAC: I know that (I checked that the last time he answered some of my questions), I just see this guy everywhere!
@Daniel be careful, might also be a case of beginning paranoia ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.