Custom fonts php-font-lib AdobeFontMetrics issue - wants to save files, no write access
So... after moving to a strictly-controlled host (there's no write access anywhere except /tmp and a local /log), I get this fatal error.
The fonts look all wonky, too. Looks like it's being rendered from UTF8 by a non-UTF-aware program, every letter is rendered k i n d a l i k e t h i s.
It looks like it's trying to write to some file (as evidenced by fwrite), but there will be no write permissions for PHP into the code directory, that's out of the question.
Ideas?
Stack trace:
PHP Fatal error: Uncaught TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool given in /var/www/api/vendor/phenx/php-font-lib/src/FontLib/AdobeFontMetrics.php:191
Stack trace:
#0 /var/www/api/vendor/phenx/php-font-lib/src/FontLib/AdobeFontMetrics.php(191): fwrite()
#1 /var/www/api/vendor/phenx/php-font-lib/src/FontLib/AdobeFontMetrics.php(211): FontLib\\AdobeFontMetrics->addLine()
#2 /var/www/api/vendor/phenx/php-font-lib/src/FontLib/AdobeFontMetrics.php(49): FontLib\\AdobeFontMetrics->startSection()
#3 /var/www/api/vendor/phenx/php-font-lib/src/FontLib/TrueType/File.php(361): FontLib\\AdobeFontMetrics->write()
#4 /var/www/api/vendor/dompdf/dompdf/src/FontMetrics.php(245): FontLib\\TrueType\\File->saveAdobeFontMetrics()
#5 /var/www/api/vendor/dompdf/dompdf/src/Css/Stylesheet.php(1511): Dompdf\\FontMetrics->registerFont()
#6 /var/www/api/vendor/dompdf/dompdf/src/Css/Stylesheet.php(1368): Dompdf\\Css\\Stylesheet->_parse_font_face()
#7 /var/www/api/vendor/dompdf/dompdf/src/Css/Stylesheet.php(302): Dompdf\\Css\\Stylesheet->_parse_css()
#8 /var/www/api/vendor/dompdf/dompdf/src/Dompdf.php(617): Dompdf\\Css\\Stylesheet->load_css()
#9 /var/www/api/vendor/dompdf/dompdf/src/Dompdf.php(695): Dompdf\\Dompdf->processHtml()
#10 /var/www/api/api-modules/func.pdf.php(294): Dompdf\\Dompdf->render()
#11 /var/www/api/api-modules/v1/rejestracja.php(131): generateAndReturnWarrantiesPDF()
#12 /var/www/api/api.php(245): include_once('...')
#13 /var/www/public/api.php(11): require('...')
#14 {main}
thrown in /var/www/api/vendor/phenx/php-font-lib/src/FontLib/AdobeFontMetrics.php on line 191
/tmp or /log ... that is strict. I'm investigating a "leave no trace" default for Dompdf that would not write anything to disk. But it's not yet in development so I'm not sure when that would be available. You can change the directory used by Dompdf for persisting fonts, but your limited options don't seem great. I imagine /tmp is cleared on a regular basis on such a host? And you don't want to clutter up /log with data files.
Any other locations where you can drop files? Short term you can use /tmp, and maybe that's fine? The "installed fonts" cache should be cleared whenever the directory is flushed.
$dompdf = new Dompdf([
"tempDir" => "/tmp"
"fontDir" => "/tmp"
]);
I think I have just come across this issue
thanks @bsweeney for the tip and I have made a frontDir in my writable space
The code where this has suddenly become and issue hasn't changed for some years
suddenly I am seeing
25 16:24:44 alpine user.notice php: Warning: fopen(/redacted/vendor/dompdf/dompdf/lib/fonts/_586f525a1ad0bb51b6e1d6d8bd47467e.ufm): Failed to open stream: Permission denied 2
Sep 25 16:24:44 alpine user.notice php: /redacted/vendor/dompdf/php-font-lib/src/FontLib/AdobeFontMetrics.php 44(0)
I've got a workaround