PHP Reddit – Telegram
PHP Reddit
34 subscribers
294 photos
39 videos
25K links
Channel to sync with /r/PHP /r/Laravel /r/Symfony. Powered by awesome @r_channels and @reddit2telegram
Download Telegram
A free Shift to configure "Fast Laravel"

After implementing the strategies on a few different Laravel projects, I got tired of copy/pasting a bunch of snippets and files.

I figured I'd automate the tedium with a Shift... So, allow me to introduce the "Fast Laravel" Shift.

This free Shift configures a new, separate static middleware group (discussed in this Laravel News article) and adds two custom middleware for page caching.

These strategies (and more) are demonstrated in my "Fast Laravel" video course. If you want to learn more about the course and benefits of caching, there was a good Reddit discussion earlier this month.

https://redd.it/1qdiyb5
@r_php
Convert vardump output to PHPStan array shapes - Hell2Shape

Hi folks! Made a CLI tool that converts var\
dump output into PHPStan type annotations. Check it out: https://github.com/Feolius/hell2shape

There's also a web version, if you want to try it without installing anything (see repo docs). Works locally in your browser without sending any data to server (thanks to php-wasm).

Useful when you need to type those messy arrays and stdClass objects, but can't be bothered to do it by hand. It's not designed to be perfect, but it provides a solid baseline for manual refinement.

Feedbacks welcome!





https://redd.it/1qdlox5
@r_php
AI generated content posts

A bit of a meta post, but /u/brendt_gd, could we please get an "AI" flair that must be added to every post that predominantly showcases AI generated content?

We get so many of these posts lately and it's just stupid. I haven't signed up to drown in AI slop. If the posters can't bother to put in any effort of their own, why would I want to waste my time with it? It's taking away from posts with actual substance.

For what it's worth, I'm personally in favour of banning slop posts under "low effort" content, but with a flair people could choose if they want to see that garbage.

https://redd.it/1qdrv9c
@r_php
Coupled vs Decoupled

What’s your approach if you’re a solo dev and you’re to build a small to medium web app.

Will you go full Laravel + blade (Coupled)?

OR

Do you prefer decoupling the backend and frontend…and use JS Frameworks (Decoupled)?

https://redd.it/1qdvr1t
@r_php
Multiplayer Game of Life

https://gameoflife.zweiundeins.gmbh

This demonstrates a Swoole app streaming 2500 divs 5 times a second to the browser via SSE. As SSE is just HTTP, it's Brotli-compressed and manages 100x compression after a few minutes, due to Brotli window spanning the entire stream. It's multiplayer, so open two tabs side by side to see. A year ago I never thought somesthing like this possible with PHP - this runs on a 20$/year VPS.

https://redd.it/1qeafok
@r_php
Running PHP on AWS Lambda as a microservice

Finally had sometime to build a quick portfolio website for myself (https://www.niwebdev.co.uk if your interested!) and because my website will get little to no traffic I thought a serverless approach would be ideal.

I'm experienced with Python and Node.Js but PHP is my goto for a web application and wanted to experiment getting it running in Lambda.

Most of the heavy work is done for you with Bref (https://bref.sh) and it makes it super easy to build and deploy your PHP application.

Here are some of my findings which you might find useful if you want to go serverless with PHP:

Load Time

Pages are loaded between 40-60ms, cold start (no traffic within about 15 minutes) means the first page load is about 200-300ms. Overall very impressive.

SSL

All traffic is routed through the AWS API Gateway. This is brilliant because it handles the SSL for you, the downside is API Gateway only supports HTTPS. If someone accidentally uses HTTP they will get a 404. For my portfolio site I don't care, but on a customer site I would use a load balancer or I think Cloudfront can handle this better.

Web Server

Running PHP on Lamba eliminates the need for a web server. No more configuring Apache / Nginix / FrankenPHP. Doesn't matter if 1000 people hit your site at the same time, AWS will handle this.

Database / Caching

My site doesn't need a database or caching, but if you want to connect to these services you will need to add a NAT to your VPC. So even though you don't need to pay for a server, you will need a NAT for any site with complexity which costs more money than the low tier EC2 instances. I think a NAT costs about $30 a month before bandwidth and other fees.

State

Traditionally PHP is stateless, meaning nothing is preserved between requests. But using Lambda the same thread/worker can be reused. Lets say when your noscript loads and you set a user into memory, if you don't clear the state between each request it is possible you expose data to the wrong user. I added a clearState() function where I put any code needed to clean up at the start of each request.

Storage

To serve your static files and storage solutions in general you must use a CDN and S3. The only writable directory in Lambda is the temporary system directory. Most modern sites don't rely on server storage anymore so this isn't really an issue. The CDN and S3 is super cheap, probably costs next to nothing for my site.

Development vs Production

In my development environment I run Bref as a docker container. My production image uses php-84-fpm and my development image uses php-84-fpm-dev. The dev image has some useful extensions needed for development.

Summary

So far I would highly recommend switching from the traditional setup and go serverless with PHP. Just take into account the cost of the NAT which I don't need anyway for my site, but have setup for other sites I have now converted to serverless PHP and trimmed over $150 a month of the AWS bill.

Converting a site is very easy, especially if you already use S3 and a CDN.

Happy to answer any questions for anyone wanting help or advice.

https://redd.it/1qeob8o
@r_php
PHP 8.5 has been released for several months, but I finally found time to update my PHP cheat sheet
https://cheat-sheets.nth-root.nl/php-cheat-sheet.pdf

https://redd.it/1qi7pyf
@r_php
Laravel E-commerce Templates Advice

Hi everyone,

I’m not very experienced with Laravel templates, but for a project I’d need some e-commerce solutions.

The goal would be to build a webshop with around 80,000 products (tires), so each product has many variants. The shop would need faceted filtering (vehicle type / tire width / height / diameter, etc.).

Product data is received once a day via API in CSV format from multiple distributors. Customers should be able to register accounts. At the moment there is no online payment processor, but it’s possible that one will be needed later.

Shop operators would of course have access to an admin interface, where they can manually edit product prices and, if necessary, the available stock quantity.

Which templates would you recommend in this space that could realistically handle these requirements?

Thanks in advance for the help, and sorry if I missed any important details, I’ll add them in an edit if something comes up.

https://redd.it/1qj0yvw
@r_php
Anyone else seeing bias about AI among Laravel devs?

I was networking with some Laravel developers over the past few weeks, and I was struck by how polarized opinions are on how revolutionary AI is for back-end development.

What’s most shocking is the perspective difference among senior developers. Some seniors claim they’ve become 10x more productive, while others say it just generates a bunch of bugs and is useless in advanced tasks.

If you’re open to sharing ... what’s your experience level, and how much do you use AI in day-to-day coding (0–5)?


0 => 'never',
1 => 'rarely',
2 => 'sometimes',
3 => 'often',
4 => 'most of the time',
5 => 'always'
;

https://redd.it/1qj4lqx
@r_php
Is Domain Driven Design just needless complexity? My limited experience with it has been mixed at best.

I don't have a lot of experience with DDD so take this post with a grain of salt. It's personal experience rather than anything else and doesn't hold univeral truth.

------

For the past 6ish months I've worked on DDD project with an established team of 5 people. I'm the new guy.

I have nothing to compare it to so I'll take their word for it.

I figured as long as I'm working with it might as well educate myself on the matter. I read Domain Driven Design by Erik Evans, and "Implementing Domain-Driven Design" by Vaughn Vernon.

I liked Vernon's book a lot. It's more hands on.

In theory DDD sound good. It's clean, scalable, easy to work with, blends business needs with coding well.

My experience in practice has been different.

I won't talk about the businesses needs and how businesses guys communicate with devs because I feel like people will have very very different experiences.

I will however like to talk, at a high level, about the effects on the code.

In the project I work with it just seems to add needless complexity for the sake of having "layers" and clean design.

I can't say I have any strong opinions on that, but I do not like writing code for the sake of more abstraction that doesn't really do anything(ironically in Vernon's book this is mentioned as one of the pitfalls).

Not to mention the PR comments tend towards zealotry, sometimes, not all the time.

Even with a debugger the code can be hard to follow. There's 3 4 layers of abstraction even for simple queries to a db.

I feel like you need a team that already has DDD experience to actually implement DDD properly.

I'd like to hear other experiences with DDD. How well did it serves you?

https://redd.it/1qi6d6j
@r_php
MoonShine 4: Laravel Admin Panel – Now with AI!

Hi everyone!

I've been working on MoonShine, an open-source admin panel for Laravel, for several years now, and I'm excited to announce MoonShine 4!

MoonShine is a simple, free admin panel for Laravel. It's good for both new and experienced users. It works with things like TailwindCSS, Laravel, and Alpine.js.

# What's new in MoonShine 4

Fast Building

Get a nearly complete admin panel right away. Don't waste time coding forms, tables, or buttons – just use the stuff that's already there. Build quickly, and you can even reuse parts of MoonShine in dashboards or other projects.

Simple Data (CRUD)

Making, reading, updating, and deleting things like users, orders, or articles is very easy. It works with databases or APIs just fine. It's easy to get started, and the code is readable.

AI Tools

* MoonVibe Generator. Build an admin panel from just one request! Simply say what you want, and it'll build a working Laravel admin panel with the database, models, migrations, and a nice look.
* Forty-Five Package. Need a user list page, a filter, and a button to add new users? Just ask, and you get a page with all of that. It actually generates code with Claude Code, it doesn't just use templates.

Fast Design Changes

Change colors, fonts, and spacing to match your style. There are over 20 ready-made color options, and you can even create your own.

Admin Panel in Telegram

Get to the admin panel from inside Telegram. You don't need a separate app!

Works with More Than Just Laravel

You can also use MoonShine in Symfony and Yii3 projects.

# Why Use It?

vs Filament: good for bigger projects. Skip Livewire and Eloquent. Also, AI generation and Telegram are ready.

vs Nova: It's free.


Try MoonShine out – you might like it!

Repo: [https://github.com/moonshine-software/moonshine](https://github.com/moonshine-software/moonshine)


I wrote more about MoonShine 4 in a [Medium article](https://medium.com/@thecutcode/moonshine-4-ai-powered-admin-panel-revolution-a76e80d2964b):

* How Forty-Five (AI assistant) is changing things
* Design token system and Tailwind 4
* Telegram MiniApp
* PHPStorm plugin
* and more



One last thing. Question:
How long does it take you to code an admin panel for a Laravel project?



https://redd.it/1qj2r8x
@r_php
Raspberry Pi 5 - Running Symphony some benchmark results

I got a bit annoyed at Digital Ocean for a hobby site I'm running. The D.O. ocean cost is just too high for something that is free and doesn't have heaps of users.

So I thought I'd grab a Pi5 16Gb, 64GB high speed SD card and see if it's a good web server.

What the real game changer is being using the Cursor Cli actually on the server.

1. I've been trying the Claude Code version, but I found you can actually run Opus 4.5 using the Cursor CLI if you have a subnoscription. This way I don't need to have both Cursor and Claude .

2. The agent was able to do all the hard configuration and setup running FrankenPhp which works amazingly well.

3. The agent does an amazing job at my devops. Really loving this. So easy to get anything done. Especially for a small hobby project like this.

I've used the agent (that's the Cursor CLI command to run any LLM model), to do my setup but I've asked it to profile my apps speed and improve it.

After talking to ChatGPT, I thought I would try the standard Raspberry Pi 5, 256Gb NVMe drive . This drive was pretty cheap, $60NZD bucks + $25 for a hat to so I could mount it on top of the Pi.

With the NVMe drive I'm able to do about 40+ requests/second. Of a super heavy homepage (has some redis caching). I've included some results below summarised by Opus, but the starting point was pretty low at 3.29 req/sec.

Some things I found fun.
1. So much fun working with an agent for devops. My skills are average but it was fun going through the motions of optimisation and performance ideas.
2. After deployment, Opus wrote me a great backup noscript and cron that work first time with log file rotation. Then upload my backups to Digital Ocean space (S3 equiv.). Wonderful
3. It was great at running apache bench and tests and finding failing points. Good to see if any of the changes were working.
4. We did some fun optimisation around memory usage, turning MySql for this processor and ram, the default configuration that gets installed is generally not turned for ram, cpu. So this probably helped a bit.

What I don't know yet. Would it have been better to buy an Intel NUC100 or something. I like the Pi a lot as they are always in stock at my computer store. So I can always find one quickly if things blow up. I do like how small the PI is, I'm not sure about power consumption. Not sure how to test, but hopefully it's efficient enough. Good for a hobby project.


Generated from AI ---- but details of setup and speed

  • Raspberry Pi 5 (16GB)

  • Symfony application

  • Caddy web server with FrankenPHP

• 64GB SD card I think its U10 high speed -> upgraded to NVMe drive (R.Pi branded 256GB standard one)



  Starting Point - Baseline (SD Card, no optimizations)



  | Concurrency | Req/sec | Avg Response | 

  |-------------|---------|--------------|

  | 10          | 3.29    | 3.0s         | 

  | 50          | 2.11    | 23.7s        | 



  Pretty painful. The app was barely usable under any load.

  Step 1: Caddy Workers (FrankenPHP)

  Configured 8 workers to keep PHP processes alive and avoid cold starts:



  | Concurrency | Req/sec | Avg Response | 

  |-------------|---------|--------------|

  | 10          | 15.64   | 640ms        | 

  | 100         | 12.21   | 8,191ms      | 



  \~5x improvement at low concurrency. Workers made a huge difference.

  Step 2: Redis Caching - The Plot Twist

  Added Redis for caching, expecting better performance. Instead:



  | Config         | 10 concurrent | 100 concurrent | 

  |----------------|---------------|----------------|

  | No cache       | 15.64 req/s   | 12.21 req/s    | 

  | Redis (Predis) | 2.35 req/s    | 8.21 req/s     | 

  | File cache     | 2.25 req/s    | 7.98 req/s     | 



  Caching made it WORSE. Both Redis and file cache destroyed performance. The culprit? SD card I/O was

  the bottleneck. Every cache read/write was hitting the slow SD card.

  Step 3: NVMe Boot

  Moved the entire OS
to an NVMe drive. This is where everything clicked:



  | Concurrency | Req/sec | Avg Response | Per Request | 

  |-------------|---------|--------------|-------------|

  | 1           | 10.64   | 94ms         | 94ms        | 

  | 10          | 39.88   | 251ms        | 25ms        | 

  | 50          | 41.13   | 1,216ms      | 24ms        | 

  | 100         | 40.71   | 2,456ms      | 25ms        | 

  | 200         | 40.87   | 4,893ms      | 24ms        | 



  Final Results: Baseline vs Optimized



  | Concurrency | Before | After | Improvement | 

  |-------------|--------|-------|-------------|

  | 10          | 3.29   | 39.88 | 12x faster  | 

  | 50          | 2.11   | 41.13 | 19x faster  | 







https://redd.it/1qijmfj
@r_php