Skip to main content
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM developerWorks : Web Architecture : Education - Tutorials
Writing efficient PHP
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPreviousNext
2. Writing efficient code

Returning content when it's available page 14 of 15

In the same performance assessment mentioned in Watching your network traffic, no data was sent back to the client browser until the entire PDF report had been generated. This was also observed by watching network traffic. When using PDFLib, you can generate PDF data directly in memory (instead of in a temporary file. Then, you can send each page of the report to the client as it is generated. The benefits of this method include:

  • Network performance is better, especially for larger reports or over slower network connections. The first page can be sent before the entire report has been generated. As soon as the first page is ready, it is sent back to the client.
  • Memory requirements on the server are reduced.
  • The need for temporary files is avoided.

By making a few small changes to the application, you can implement this streaming of the reports as they are generated.

Ideally, the first page of the report is displayed as soon as it is received by the client browser. Limitations of the PDF format in use make this impossible. Adobe Acrobat Reader does support a Web-optimized PDF format that is more suitable in this instance. As of this assessment, PDFLib does not support output in this Web-optimized format.

Tip: Be careful not to send content back in blocks that are too small. You don't want to generate a large amount of extra network traffic. In the application mentioned above, sending back one PDF page at a time was a reasonable compromise between frequency of data sent back to the client and size of the data returned.

Main menuSection menuFeedbackPreviousNext
Privacy Legal Contact