1

I'm currently using the Symfony Process component, which relies on the proc_open function of PHP. I need to launch a command to wkhtmltopdf, which has this form :

/usr/local/bin/wkhtmltopdf --window-status "___RENDER_PDF___" --orientation "portrait" --run-script "window.basilOptions = {storages: ['memory'] }; document.body.addEventListener('status:app:rendered', function () { window.status = '___RENDER_PDF___'; });" "http://localhost/p/lps#poll/lpsp002" "/tmp/pdf_d6fbWO"`

When I run this command directly on my shell, it works just fine and takes about 6 seconds to be executed. But when I'm using PHP with the Process Component, it goes into a timeout... And when using the exec or proc_open functions, it runs indefinitely. The default timeout for the Process Component is 60 seconds (even extending it doesn't have any effect).

I tried this on PHP 5.4 and PHP 5.5, but the result seems to be same.

Any ideas why this command runs just fine on the shell but not through PHP ? Tested on MAMP and not MAMP environments (on 5.4 and 5.5 versions). It works on Ubuntu 14.04 with PHP 5.5 though.

I thought that maybe, when getting through PHP and MAMP, the process could be completed but still hangs as was reported with this bug ? I'll update when i'll have some more information, to see if the PDF is indeed generated or not.

Thanks.

luchaninov
  • 6,792
  • 6
  • 60
  • 75
Talus
  • 754
  • 7
  • 18
  • Why don't you just use KnpSnappyBundle - http://knpbundles.com/KnpLabs/KnpSnappyBundle ? – dmnptr Jul 21 '14 at 15:16
  • It is faster to use directly the Symfony Process component, and I need to build some parameters first, where Snappy is less flexible. But the problem will be the same anyway... – Talus Jul 21 '14 at 15:40

1 Answers1

2

The problem could be caused by session locking - current PHP page thread locks session for writing, so another page on the same server waits for session to be unlocked (on sessions_start() function) to process request (dumping into PDF). This creates dead lock, because session by default starts with write lock for other threads.

To prevent this session deadlock, close session for write by adding session_write_close(); before command and if you need write to session again just after PDF is rendered add session_start(); after PDF rendering

Maciej Pyszyński
  • 9,266
  • 3
  • 25
  • 28