1
I own a Symfony2 project that generates a PDF from an HTML with Bundle KnpSnappyBundle
, that is dependent on Bundle KnpSnappy
and which, in turn, makes the abstraction with the executable wkhtmltopdf
.
This binary is executed with the appropriate parameters through the function proc_open
PHP as per line below:
$process = proc_open($this->command, $descriptorspec, $pipes, null, $this->env);
In the tests I did, I noticed that the process gets stuck with the Apache process. So if the server is overloaded, the Apache response may take a long time, which is not an option.
Changing the function as well or the Bundle functionality is not an option either. The only things I can do is modify the function parameters proc_open
so that the process doesn’t get stuck with Apache - if this option exists.
Has anyone done anything like this or knows any workaround?
Look, I’ve been through this problem too, a workaround I did at the time was to use a proc_open on an SSH and execute the command I wanted in SSH assigning the process to the background, then disconnecting. But it’s one of those tricks. But it works, because I was lifting services and I couldn’t leave my application hanging on them.
– Gabriel Gartz
@Gabrielgartz the solution I found would be to put a
&
at the end of the command, but as generation process is quite encapsulated, I have no way to do this.– Rodrigo Rigotti
It is the problem of using & at the end, which you run in the background but the process is tied to whoever fired it, that is, if you kill the PHP process (which tends to end at the end of the script) it will stop the hanging process and if it is not finished, it will be canceled.
– Gabriel Gartz