0

I have a simple command line here.. If I run it from a terminal it completes in about 1-2 sec, but if running it from php it never stops executing!? Why is that?

xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf /var/www/input.html /var/www/output.pdf

from php

exec('xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf /var/www/input.html /var/www/output.pdf');

with sudo

sudo -u www-data xvfb-run -a -s "-screen 0 640x480x16" /usr/bin/wkhtmltopdf /var/www/input.html /var/www/output.pdf

This doesn't create the output file but returns an error

Loading page (1/2)
Printing pages (2/2)
QPainter::begin(): Returned false
Done
Exit with code 1 due to network error: ProtocolUnknownError

pipe stdout/stderr

Here both xcfb.err and xvfb.out are created but both files are empty. The command never completes executing

exec('xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf '.$path.'/email.html '.$path.'/output.pdf > '.$path.'/xvfb.out 2> '.$path.'/xvfb.err');
clarkk
  • 27,151
  • 72
  • 200
  • 340
  • Maybe your PHP has an endless loop and the command is actually being executed multiple times. It's impossible to tell without looking at the rest of your code. – Mike Nov 27 '15 at 20:23
  • no its not.. the script only has this one line – clarkk Nov 27 '15 at 20:25
  • 1
    Try `exec('whoami');` to figure out which user PHP is being executed as. If that is different than the user you are executing it by the command line with try doing, for example `sudo -u www-data xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf /var/www/input.html /var/www/output.pdf` (substitute `www-data` for the actual user) and see what happens. – Mike Nov 27 '15 at 20:32
  • (the second command you execute by command line, the first in PHP, in case that wasn't clear) – Mike Nov 27 '15 at 20:33
  • Also, if you don't have `sudo` use `su - -c ""` – Mike Nov 27 '15 at 20:37
  • Try also once redirecting error output: `exec('xvfb-run ... > /tmp/xvfb.out 2> /tmp/xvfb.err');`. It looks like xvfb-run is asking for input or something like that. You might even try piping `yes` before xvfb-run, just in case(`'yes | xvfb-run ...'`). – LSerni Nov 28 '15 at 08:15
  • Have just tried your last command.. both `xvfb.err` and `xvfb.out` is created but empty.. No `output.pdf` and the command never completes executing – clarkk Nov 28 '15 at 10:11

0 Answers0