shadkamel liked a comment+100 XP
1w ago
shadkamel wrote a reply+100 XP
1w ago
shadkamel liked a comment+100 XP
1w ago
I know you already switched to dompdf, but if you ever need modern CSS (flexbox/grid) back, here is the actual solution. The AI completely missed the root cause.
The specific error not a snap cgroup happens because recent Ubuntu versions on Forge install Chromium as a Snap package. Snap's strict AppArmor/cgroup confinement blocks it from being executed by daemon services like php-fpm. Running config:cache likely just triggered a worker/FPM restart that temporarily masked the issue before the cgroup restrictions clamped down again.
To fix it permanently, you need to ditch the Snap version entirely and install the native Google Chrome binary.
SSH into Forge and nuke the snap version:
sudo snap remove chromium
Install the native Google Chrome package:
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get install -y google-chrome-stable
Update your PDF generation:
return Pdf::view('PDF.invoice', compact('invoice'))
->format('a4')
->landscape()
->name("{$invoice->invoice_no}-{$invoice->created_at->format('Y-m-d')}.pdf")
->withBrowsershot(function ($browsershot) {
$browsershot->setChromePath('/usr/bin/google-chrome-stable')
->addChromiumArguments(['--no-sandbox', '--disable-setuid-sandbox']);
})
->download();
Dompdf is fine for basic tables, but applying this fix takes 2 minutes and gets Spatie/Browsershot running flawlessly on Forge forever.
shadkamel wrote a reply+100 XP
2w ago
shadkamel liked a comment+100 XP
2w ago
Best bet would be to use use chatgpt and follow through. And give it every error that you get. I was able to use it twice to get browsershot working on a web app running in forge. Better still you can checkout or use https://github.com/barryvdh/laravel-dompdf
shadkamel wrote a reply+100 XP
2w ago
shadkamel started a new conversation+100 XP
2w ago
hello, i have used the spatie laravel pdf for generating an invoice that work with browsershot, every thing is working in locale and production (laravel forge), after an hour or maybe two, the pdf generator will crash on production, here is the error:
The command "PATH=$PATH:/usr/local/bin NODE_PATH="/home/forge/sl-trucks.com/releases/67020047/node_modules" "/usr/bin/node" '/home/forge/sl-trucks.com/releases/67020047/vendor/spatie/browsershot/src/../bin/browser.cjs' '-f file:///home/forge/sl-trucks.com/releases/67020047/storage/temp/943269296-0594054001775539573/command.js'" failed. Exit Code: 1(General error) Working directory: /home/forge/sl-trucks.com/releases/67020047/public Output: ================ Error Output: ================ Error: Failed to launch the browser process: Code: 1 stderr: /system.slice/php8.4-fpm.service is not a snap cgroup for tag snap.chromium.chromium TROUBLESHOOTING: https://pptr.dev/troubleshooting at ChildProcess.onClose (/home/forge/sl-trucks.com/releases/67020047/node_modules/@puppeteer/browsers/lib/cjs/launch.js:350:24) at ChildProcess.emit (node:events:531:35) at ChildProcess._handle.onexit (node:internal/child_process:293:12)
when i run php artisan config:cache it will work again for two house then it will crash again, does any one have a clue how to solve this problem?
here is an example of the controller method:
return Pdf::view('PDF.invoice', compact('invoice'))
->format('a4')
->landscape()
->name("{({$invoice->invoice_no})-{$invoice->created_at->format('Y-m-d')}.pdf")
->download();
shadkamel wrote a comment+100 XP
4w ago
shadkamel wrote a comment+100 XP
1mo ago
there is another tool that can be useful just like laravel debugbar which is clockwork, i so usefull if you want to debug api requests which tell you memoery usage, models, queries and more.
here is the link: https://underground.works/clockwork/
shadkamel wrote a comment+100 XP
4mos ago
shadkamel liked a comment+100 XP
4mos ago
Quick note! At 13:07, we use the Bot's chat id to compare it to the authorized user id. Technically, this works for a private chat with the Bot. However, we should handle the possibility of group chats and channels by instead fetching the user directly. It's more clear that way, anyhow.
Use $bot->user()->id instead of $bot->chat()->id.
if ($bot->user()->id !== config('nutgram.authorized_user') {
$bot->sendMessage('You are not authorized to use this bot.');
}
shadkamel wrote a comment+100 XP
4mos ago
shadkamel wrote a comment+100 XP
4mos ago