php-wkhtmltox icon indicating copy to clipboard operation
php-wkhtmltox copied to clipboard

500 error

Open gour opened this issue 15 years ago • 17 comments

Hello!

I'm trying to see if wxhtmltox could replace html2pdf lib in Simple Invoices application.

phpinfo shows that extension is enabled (0.10.0_beta5 ), but loading test_pdf.php script gives 500 error (Cherokee server).

Any hint how to troubleshoot it?

gour avatar Sep 21 '10 14:09 gour

Here is the trace: http://pastebin.com/cQbaSqcS

gour avatar Sep 21 '10 15:09 gour

make sure the process that the script is running as is able to write to the directory where the test.pdf is being written.

try changing the output directory to /tmp/test.pdf and see if that works

mreiferson avatar Sep 21 '10 20:09 mreiferson

I set dir to 777 and there is still problem.

However, after changing setup in my server to use php-cgi instead of php-fpm, I've found the following in my error.log file:

wkhtmltox: cannot connect to X server

gour avatar Sep 22 '10 05:09 gour

this is actually an issue with the library this extension wraps, libwkhtmltox. It requires that you have the X11 libs installed (but does not require an X11 server to be running)

Try installing X11 libs...

mreiferson avatar Sep 22 '10 13:09 mreiferson

this is actually an issue with the library this extension wraps, libwkhtmltox. It requires >that you have the X11 libs installed (but does not require an X11 server to be running)

but i'm testing on full-fledged X desktop running LXDE on my desktop (localhost) machine, so, X11 libs are installed.

gour avatar Sep 22 '10 13:09 gour

can you confirm that the command line version of wkhtmltopdf works correctly?

Did you compile libwkhtmltox from source?

mreiferson avatar Sep 22 '10 13:09 mreiferson

can you confirm that the command line version of wkhtmltopdf works correctly?

[gour@atmarama gour] wkhtmltopdf http://simpleinvoices.org/ si.pdf Loading page (1/2) Printing pages (2/2)
Done

Did you compile libwkhtmltox from source?

yes

gour avatar Sep 22 '10 14:09 gour

what about trying to run wkhtmltopdf (CLI version) as the same user that php-fcgi runs as? I'm guessing that user isn't allowed to access the X11 server...

mreiferson avatar Sep 22 '10 14:09 mreiferson

what about trying to run wkhtmltopdf (CLI version) as the same user that php-fcgi runs as? I'm guessing that user isn't allowed to access the X11 server...

well, i executed wkhtmltopdf as user 'gour' and here is the part of 'ps -ef' output:

gour 8371 4700 0 07:11 ? 00:00:01 /usr/sbin/cherokee-worker gour 8414 4700 0 07:11 ? 00:00:00 /usr/bin/php-cgi -b 127.0.0.1:47990 gour 8417 8414 0 07:11 ? 00:00:00 /usr/bin/php-cgi -b 127.0.0.1:47990 gour 8418 8414 0 07:11 ? 00:00:00 /usr/bin/php-cgi -b 127.0.0.1:47990 gour 8419 8414 0 07:11 ? 00:00:00 /usr/bin/php-cgi -b 127.0.0.1:47990 gour 8420 8414 0 07:11 ? 00:00:00 /usr/bin/php-cgi -b 127.0.0.1:47990 gour 8515 8414 0 07:15 ? 00:00:00 /usr/bin/php-cgi -b 127.0.0.1:47990

so you can see that php-cgi runs as 'gour' as well as Cherokee webserver.

Any idea?

gour avatar Sep 22 '10 15:09 gour

what happens when you run the test_pdf.php script from the command line:

$ php test_pdf.php

Also - in the wkhtmltopdf tree theres a directory called examples - make it. It will produce a binary, pdf_c_api, that tests usage of libwkhtmltox.

mreiferson avatar Sep 22 '10 19:09 mreiferson

what happens when you run the test_pdf.php script from the command line:

$ php test_pdf.php

Nothing, iow. no errors.

Also - in the wkhtmltopdf tree theres a directory called examples - make it. It will produce a binary, pdf_c_api, that tests usage of libwkhtmltox.

[gour@atmarama examples] ./pdf_c_api Loading page Printing pages Done httpErrorCode: 0

Anything else?

gour avatar Sep 22 '10 19:09 gour

can you run a single worker instance of php-cgi and produce a strace or gdb output of what it's trying to do when that script is run?

mreiferson avatar Sep 22 '10 20:09 mreiferson

Here it s: http://pastebin.com/PubrADFT (strace.log), but being quite new with strace, I'm not sure if it will be useful.

or this one: http://pastebin.com/FNJ3t9m0

gour avatar Sep 23 '10 06:09 gour

i've updated the git repository to address this issue

please recompile, test, and confirm it's working correctly

mreiferson avatar Oct 29 '10 18:10 mreiferson

I've tried, but have problem...

Here is the snippet from ./configure:

checking for libwkhtmltox support... yes, shared
found in /usr
checking for wkhtmltopdf_init in -lwkhtmltox... yes

which, imho, looks good, but 'make install' fails:

[gour@atmarama php-wkhtmltox] su -c "make install"
Password: 
/bin/sh /home/gour/repos/git/php-wkhtmltox/libtool --mode=compile cc  -I. -I/home/gour/repos/git/php-wkhtmltox -DPHP_ATOM_INC -I/home/gour/repos/git/php-wkhtmltox/include -I/home/gour/repos/git/php-wkhtmltox/main -I/home/gour/repos/git/php-wkhtmltox -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /home/gour/repos/git/php-wkhtmltox/phpwkhtmltox.c -o phpwkhtmltox.lo 
mkdir .libs
 cc -I. -I/home/gour/repos/git/php-wkhtmltox -DPHP_ATOM_INC -I/home/gour/repos/git/php-wkhtmltox/include -I/home/gour/repos/git/php-wkhtmltox/main -I/home/gour/repos/git/php-wkhtmltox -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/gour/repos/git/php-wkhtmltox/phpwkhtmltox.c  -fPIC -DPIC -o .libs/phpwkhtmltox.o
/home/gour/repos/git/php-wkhtmltox/phpwkhtmltox.c: In function ‘zm_shutdown_phpwkhtmltox’:
/home/gour/repos/git/php-wkhtmltox/phpwkhtmltox.c:27:9: error:   wkhtmltoimage_initialized’ undeclared (first use in this function)
/home/gour/repos/git/php-wkhtmltox/phpwkhtmltox.c:27:9: note: each undeclared identifier is reported only once for each function it appears in
/home/gour/repos/git/php-wkhtmltox/phpwkhtmltox.c: In function ‘zif_wkhtmltox_convert’:
/home/gour/repos/git/php-wkhtmltox/phpwkhtmltox.c:106:14: error: ‘wkhtmltoimage_initialized’ undeclared (first use in this function)
make: *** [phpwkhtmltox.lo] Error 1

gour avatar Oct 31 '10 08:10 gour

gour, I've corrected this error, please pull and try again.

thanks.

mreiferson avatar Oct 31 '10 17:10 mreiferson

Build works now, but, again, I get 500 error.

gour avatar Oct 31 '10 20:10 gour