symfonyknp-snappy

Symfony 6 - Unable to launch a new process while generating pdf


Every night in a crontab, in my production environment, I run a command who generates and send pdfs with knplabs/knp-snappy-bundle (1.9.2)

It fails every time with this log :

[2024-01-16T00:30:02.173629+01:00] cron.ERROR: Unable to launch a new process. [] []
[2024-01-16T00:30:02.174059+01:00] cron.ERROR: 
#0 /var/www/html/vendor/symfony/process/Process.php(249): Symfony\Component\Process\Process->start(NULL, Array)
#1 /var/www/html/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php(608): Symfony\Component\Process\Process->run()
#2 /var/www/html/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php(197): Knp\Snappy\AbstractGenerator->executeCommand('wkhtmltopdf --z...')
#3 /var/www/html/vendor/knplabs/knp-snappy/src/Knp/Snappy/Pdf.php(36): Knp\Snappy\AbstractGenerator->generate(Array, '/tmp/knp_snappy...', Array, false)
#4 /var/www/html/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php(246): Knp\Snappy\Pdf->generate(Array, '/tmp/knp_snappy...', Array)
#5 /var/www/html/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php(265): Knp\Snappy\AbstractGenerator->getOutput(Array, Array)
#6 /var/www/html/src/Service/DocumentModeleService.php(309): Knp\Snappy\AbstractGenerator->getOutputFromHtml('<!DOCTYPE html>...', Array)
#7 /var/www/html/src/Service/DocumentModeleService.php(253): App\Service\DocumentModeleService->generatePDFFromHtml('<!DOCTYPE html>...', Object(App\Entity\DocumentModele), Array)
...

if i run the same command after connecting to my production environment (not at 00:30 AM), it runs perfectly without error

How can I find the problem ?

i founc people having trouble while opening a lot of files but this is not may case because i send les than 5 pdf each times it runs

below the ulimit command output :

root@cron-7867db8779-srzzc:/var/www/html# ulimit -a
real-time non-blocking time  (microseconds, -R) unlimited
core file size              (blocks, -c) unlimited
data seg size               (kbytes, -d) unlimited
scheduling priority                 (-e) 0
file size                   (blocks, -f) unlimited
pending signals                     (-i) 63562
max locked memory           (kbytes, -l) unlimited
max memory size             (kbytes, -m) unlimited
open files                          (-n) 65535
pipe size                (512 bytes, -p) 8
POSIX message queues         (bytes, -q) 819200
real-time priority                  (-r) 0
stack size                  (kbytes, -s) 8192
cpu time                   (seconds, -t) unlimited
max user processes                  (-u) unlimited
virtual memory              (kbytes, -v) unlimited
file locks                          (-x) unlimited

Solution

  • Problem solved changing the /root directory permissions

    When the command was launched by the cron, the current working directory was "/root". and the permissions were drwx------

    i changed it to drwx--x--x to allow exécution from this folder