-
Notifications
You must be signed in to change notification settings - Fork 438
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
Symfony\Component\Process\Exception\ProcessTimedOutException on PDF generation #169
Comments
@sn0opr I have good news and bad news for you. snappy/src/Knp/Snappy/AbstractGenerator.php Line 102 in 3aaabad
Cheers. |
@sn0opr My guess is that it comes from wkhtmltopdf, not snappy. |
@akovalyov Hi, thank you for the fast reply. 1 - I'm generating pdf from local resources 4 - I removed the css files from the 5 - I tried the Symfony class
The Win Server machine is 12GB of RAM and Xenon Processor |
Interesting: So it's definitly a problem with the Process execution. You can try to find existing issues on https://github.com/symfony/symfony/issues?q=is%3Aopen+is%3Aissue+label%3AProcess |
@sn0opr have you tried to execute wkhtmltopdf command manually in Windows cmd? |
@akovalyov Like I said, yes I did and it's works perfectly, I changed my pdf script from returning pdf file with Snappy to returning html file and tested with command line, it dose the job in a very small time. here is the output:
|
@sn0opr you can try to narrow the problem: try with php -a:
|
@docteurklein thank you for trying to help me,
result: |
for proc open, you should use:
Also, proc_open doesn't return anything, but you can still look at the file rihane.pdf and see if it worked. |
So, if proc_open fails, then it's a problem with php's http://php.net/proc_open. |
@docteurklein sorry for the late, I tested with array_map function and I got an error:
Output :
|
@docteurklein @akovalyov , I just found a solution. protected function executeCommand($command)
{
/*if (class_exists('Symfony\Component\Process\Process')) {
$process = new \Symfony\Component\Process\Process($command, NULL, $this->env);
if ($this->timeout !== false) {
$process->setTimeout($this->timeout);
}
} else {
$process = new Process($command, $this->env);
}*/
$process = new Process($command, $this->env);
$process->run();
return array(
$process->getExitCode(),
$process->getOutput(),
$process->getErrorOutput(),
);
} Can you please provide an option to use Symfony's Process class or the default one ?. |
see #166 |
@sn0opr you can install it as |
I don't get the point, looks like @sn0opr say that it works with the Process class from snappy and you removed it in #166 to force usage of the one from Symfony ? I have the same problem and using 0.4 and forcing snappy to use its own Process class works for me too. It's also a lot more faster (for the same HTML, something like 2 seconds between the button click and the PDF show with your Process class and more than 4 seconds with Symfony Process class). |
@osaris thank for the feedback. Could you give a little bit more of details about the environment and the input options for Snappy? For how many iterations have you launched it? @jeremyb do you still have Windows env to test the Snappy performance with Symfony/Process? :) |
@akovalyov on my dev machine (OSX), on 5 runs with the same HTML to convert to PDF the time is very similar. On our production environment (Windows 2008 R2, Apache 2.4, PHP 5.6.10, Laravel 5.1), I need to remove the css link to have it working with Symfony2 Process (it's ok with Snappy Process class), but the results are very different, on 10 runs with Snappy Process class, average speed is 561ms to get the PDF, with Symfony2 Process class it's 2.61 seconds !! Despite the performance issue, my main problem is that I can't use css link If I use the Symfony2 Process class but it's ok with Snappy Process class. |
+1 to have abiltiy to chose type of processor, symfony or native |
+1 |
Interesting. We removed the embedded Process class because iti didn't work well on many setups. The best would be to concentrate on fixing it, not snappy. |
@docteurklein make sense for me, the related issue on symfony part seems to be this one : symfony/symfony#15278 |
BTW, you could try to put enhanceWindowsCompatibility to false, just to try. |
@docteurklein can I change this setting in my snappy configuration file or somewhere else in my app ? |
@osaris @docteurklein is talking about https://github.com/symfony/symfony/blob/5f36605e0e2264a1f52a8caa4bbe35a6f4ece8b4/src/Symfony/Component/Process/Process.php#L1174. You can also try to experiment with |
Sorry for the delay. enhanceWindowsCompatibility don't change anything. Same for bypass_shell and suppress_errors. |
I have the same issue with the process component (see symfony/symfony#15278 (comment)) It would be awesome to be able to choose the old Snappy Process class instead of the Symfony Component. |
I only have this issue when I pass on my PHPSESSID cookie to the process. $snappy->setOption(
'cookie',
[ 'PHPSESSID' => $this->request->cookies->get('PHPSESSID') ]
); The generated pdf is correct though. It's just the Symfony Process that isn't stopping with this option. I don't yet know why the Symfony Process fails on it though. |
Hmm, it seems like the script is in fact hanging, since the pdf is only written after the timeout has been reached (and the script is thus terminated using a termsign 15. The pdf looks correct though, and the exact same command runs perfectly on the CLI. I've now worked around it using use Symfony\Component\Process\Exception\ProcessTimedOutException;
$snappy->setTimeout(3);
try {
$snappy->generate($input, $output);
} catch (ProcessTimedOutException $e) {
// do nothing, the pdf is probably generated
} It's not that clean, because other reasons the process timed out aren't handled anymore, but it works for now (if the pdf is generated in 3 seconds) |
FYI, my problem was that some external links (CSS etc) weren't accessibles from the server that is running wkhtmltopdf (DNS misconfiguration). wkhtmltopdf is really slow to give up on missing ressources so the generation time was over 30 sec. I fixed the problem by using realpath() to use local path for these ressources. |
Again returning to this issue, I suddenly only get timeouts (existing project), but the files are generated. Replacing the Symfony Process in the AbstractGenerator fixed it, so not sure why the Symfony Process is not responding.. protected function executeCommand($command)
{
exec($command, $output, $status);
return array($status, $output, $status == 0 ? '' : $output);
} |
On our dedicated the timeout issue was solved by disabling ipv6. |
I close this issue because it is pretty old now and the only updates in the past year is about networking issues leading to timeouts. If you still face a similar problem please open a new issue. |
I'm using Laravel Snappy package, and I think the problem is from Snappy itself.
In my localhost (Windows 7 32bit)
wkhtmltopdf 0.12.2.3 (with patched qt)
everything is working fine.In the deployment machine (Windows Server 2012 R2 64bit)
wkhtmltopdf 0.12.2.4 64bit
, it takes about 60 seconds without any response or error... Good news I'm using Bugsnag service to track bugs and errors, and this is what I get:Symfony\Component\Process\Exception\ProcessTimedOutExceptionGET /gca/public/demandes-achat/1138/pdf The process "C:\xampp\htdocs\gca/wkhtmltopdf/bin/wkhtmltopdf.exe --lowquality "C:\Windows\TEMP\knp_snappy55a4f9ff7f5862.10272127.html" "C:\Windows\TEMP\knp_snappy55a4f9ff7fab55.21457299.pdf"" exceeded the timeout of 60 seconds.
But when I tested to generate pdf from a website like google, it works fine !, with a plain html it wroks fine too.
I'm getting crazy here because it's working on my dev machine Win 7 and my computer Win 8.1 with difference wkhtmltopdf version for sure...
Btw, I'm using Bootstrap.min.css and Fontawesome.css
Please help me it's urgent.
The text was updated successfully, but these errors were encountered: