How to Get dependency of a PHP script?

  • Added:
  • |
  • In: Basic PHP

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?

This Question Has 1 Answeres | Orginal Question | Shubham

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.


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

I am...

Sajjad Hossain

I have five years of experience in web development sector. I love to do amazing projects and share my knowledge with all.

Connect Social With PHPAns