Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF reports not generating under HHVM 3.12.0 #9952

Closed
kofi1995 opened this issue Mar 21, 2016 · 5 comments
Closed

PDF reports not generating under HHVM 3.12.0 #9952

kofi1995 opened this issue Mar 21, 2016 · 5 comments
Labels
answered For when a question was asked and we referred to forum or answered it. Bug For errors / faults / flaws / inconsistencies etc.
Milestone

Comments

@kofi1995
Copy link

Hello,
I'm running PIWIK on a VPS with Ubuntu 15.04, HHVM 3.12.0 and NGINX 1.9.10. I have both PHP 5.6.4 and HHVM installed on that server. I use PHP to serve old web applications and HHVM for modern ones.

PIWIK works great under HHVM and reduces CPU load but PDF reports cannot be generated under HHVM.

I created a personal daily, weekly and monthly email report for one of my tracking sites under my account. On the reports table, there is an option to download the PDF.

When it is clicked this is the error message that comes up:
http://snag.gy/5td22.jpg

When I switch from HHVM to PHP, the PDF works flawlessly.

@emirb
Copy link

emirb commented Mar 21, 2016

Seems that when using HHVM, Piwik's API renderer sets wrong response format (XML).

PDF file format requires EOF to be used as file trailer, on the last line of the content.
This is done in https://github.com/tecnickcom/TCPDF/blob/develop/tcpdf.php#L9988

Piwik's API renderer appends XML response to valid PDF content, resulting in garbaged output:

... PDF content
0000413826 00000 n
0000414317 00000 n
0000414489 00000 n
0000414685 00000 n
0000414750 00000 n
0000414950 00000 n
0000419257 00000 n
trailer
<< /Size 24 /Root 23 0 R /Info 21 0 R /ID 
[ <8aeb203749d4538ab33be9cb9db12ceb> <8aeb203749d4538ab33be9cb9db12ceb> ] >>
startxref
419506
%%EOF
<?xml version="1.0" encoding="utf-8" ?>
<result></result>

Therefore, the browser cannot show the PDF content correctly, and shows you the XML error message instead.

Furthermore, when using HHVM instead of PHP engine, even though TCPDF is already setting correct Content-Type header when generating inline browser output (https://github.com/tecnickcom/TCPDF/blob/6.2.12/tcpdf.php#L7624), the actual header's value being sent is text/xml.

Content-Type: text/xml; charset=utf-8
X-Powered-By: HHVM/3.12.1
Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1
Content-Disposition: inline; filename="All_Websites_-_Sunday_March_20_2016_-_test.pdf"

Correct response headers using PHP 5.6.19:

Content-Type: application/pdf
Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1
Content-Disposition: inline; filename="All_Websites_-_Sunday_March_20_2016_-_test.pdf"

Temporary solution

You can bypass this behaviour by appending &format=original parameter into the PDF report URI. That will show the report in your browser correctly, by setting correct Content-Type response header and also disabling the additional XML output being appended.

LTS solution

This issue requires thorough investigation, but from what I can see so far, here would be some proposed solutions:

That way we would ensure that there is no extra content appended to the inline browser PDF output.

@tsteur
Copy link
Member

tsteur commented Mar 29, 2016

@emirb thank you a lot for investigating and giving us insights into the problem. 👍 👍

I haven't tried to reproduce it but wonder if this PR maybe kind of fixed the content type issue: #9700

@kofispaceman or @emirb can you maybe try with latest beta version 2.16.1 (at least 2.16.1-b2 or master branch)

@tsteur tsteur added the Bug For errors / faults / flaws / inconsistencies etc. label Mar 29, 2016
@mattab
Copy link
Member

mattab commented Mar 31, 2016

Hi @kofispaceman - do you still have the issue with our latest beta? please let us know http://piwik.org/faq/how-to-update/faq_159/

@mattab mattab added this to the 2.16.x (LTS) milestone Mar 31, 2016
@kofi1995
Copy link
Author

kofi1995 commented Apr 3, 2016

Hello @mattab and @tsteur,

I will test the latest beta and let you guys know. @emirb was right. HHVM was rendering the content as XML instead of PDF.

@mattab
Copy link
Member

mattab commented Jul 18, 2016

Hi @kofispaceman @emirb let us know if the issue is still here

@mattab mattab closed this as completed Jul 18, 2016
@mattab mattab added the answered For when a question was asked and we referred to forum or answered it. label Jul 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it. Bug For errors / faults / flaws / inconsistencies etc.
Projects
None yet
Development

No branches or pull requests

4 participants