Memory optimisation
Informations
Author: Philip Clarke
License: Freeware
Description
Normally FPDF compresses the entire PDF in the _putpages() method at the very end of PDF
generation, this can lead to a large uncompressed PDF being stored in memory.
This modification compresses each finished page in _endpage() reducing the overall memory
usage when generating large PDFs.
To test with minimal external influences, use a file such as the provided test.php. In one
terminal window as root run top like so:
~> top -q | grep php
then run the script from the command line, using:
~> php -q test.php > with_opt.pdf
The "top" terminal window will scroll detailing memory usage of php (press q to exit).
Then altering test.php to use the base class and running:
~> php -q test.php > no_opt.pdf
will show the original behaviour giving identical sized PDF files (no_opt.pdf and
with_opt.pdf). On a 600 MHz dual processor typical results were that the optimised php
code uses a maximum of 7.3 Megabytes wheareas the original uses 15 M. Both tests
typically take 2 minutes 15 secs. Over very large reports (2000 pages +) the optimised
version is very slightly slower by a few seconds.