PHP Reddit – Telegram
PHP Reddit
34 subscribers
291 photos
37 videos
24.9K links
Channel to sync with /r/PHP /r/Laravel /r/Symfony. Powered by awesome @r_channels and @reddit2telegram
Download Telegram
Symfony Messenger standalone, getting retry to work

I've managed to get Symfony Messenger to work with my legacy system using RabbitMQ. It works like a charm for the most part, what I'm trying to get working now is the retry mechanism.

ChatGPT is some help but mostly it just leads me astray into the wrong alley.

This is the code I've got so far, what glue is missing to get the RetryStrategy into this setup?

class MessagesFactory {
public static function createMessageBus(): MessageBus {
$handlers = new HandlersLocator(
AbstractCommand::class => [new class {
public function __invoke(AbstractCommand $command) {
$command->execute();
}
},
]);

$transportLocator = new TransportLocator(
'async' => self::getTransport()
);

$sendersLocator = new SendersLocator(
AbstractCommand::class => ['async',
], $transportLocator);


// Build the bus with both middlewares
return new MessageBus(
new SendMessageMiddleware($sendersLocator),
new HandleMessageMiddleware($handlers),
);
}

public static function createWorker(): Worker {
return new Worker(

'async' => self::getTransport()
,
MessagesFactory::createMessageBus()
);
}

private static function getTransport($queue = 'messages') {
$connection = Connection::fromDsn(
RABBITMQDNS . $queue
);


// TODO: Where does this go??
$retryStrategy = new MultiplierRetryStrategy(
maxRetries: 3,
delayMilliseconds: 1000,
multiplier: 2.0,
maxDelayMilliseconds: 10000
);

$transport = new AmqpTransport($connection);

return $transport;
}
}

https://redd.it/1l70qjk
@r_php
Should Laravel adopt OpenTelemetry?

OpenTelemetry (OTel) is quickly becoming the standard for observability — helping apps generate consistent data across Metrics, Events, Logs, and Traces (MELT). It allows you to track what’s happening across your system, end-to-end, and send that data to any platform (Grafana, Datadog, Honeycomb, etc.).

Laravel already gives us Telescope, which is a great tool for introspecting the application — logging requests, jobs, queries, exceptions, and more. Now, with Laravel Nightwatch on the way.

Isn’t this the perfect moment to adopt OpenTelemetry in the Laravel ecosystem?

Imagine if the framework could generate MELT data natively — and send it to Telescope, Nightwatch, or any OpenTelemetry-compatible backend without choosing one over the other.

I know Spatie is working on this direction too, which is exciting.

But should this become a first-class concern at the framework level?

What do you think? Are you using OpenTelemetry already?

Would love to hear your thoughts.

https://redd.it/1l7sde6
@r_php
composer-attribute-collector running as a command

I made some changes to my attribute collector for Composer to avoid issues with incompatibilities between Composer and the application dependencies; for example, the PSR logger with incompatible signatures. I have a branch ready, and I'm looking for brave souls to test the changes. Thanks for your help!

https://github.com/olvlvl/composer-attribute-collector/pull/35

https://redd.it/1l8o7h0
@r_php
Anyone using bun in production?

Virtually all my projects are built with inertia and react, just curious if anyone has made the switch to bun and found it to be a smooth switch from node.

https://redd.it/1l8rqn2
@r_php
Anyone can help me with PHP routing, using MVC architecture?

Hello, so im creating a budget travel planner system using PHP PDO, in mvc architecture form. I've almost finished most of the functions and have been testing with dummy views but now I recieved the frontend from my group member and need it to link it.
However, im really struggling with that and the routing part, so can anyone help me with this, please?

for example, this is my user controller :

<?php
session_start();
require __DIR__ . '/../models/User.php';
include_once __DIR__ . '/../helpers/session_helper.php';

class UserController {

private $userModel;
public function __construct(){
$this->userModel = new User;
// $this->userModel = new User($pdo);
}
// register user
public function registerUser(){

// if register button was clicked in the form // LOOK
if (($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['registerUser']))
{
// lets sanitize the data to remove any unneccesary data
$firstName = filter_var(trim($_POST['firstName']), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$lastName = filter_var(trim($_POST['lastName']), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$contactNumber = filter_var(trim($_POST['contactNumber']), FILTER_SANITIZE_NUMBER_INT);
$email = filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL);
$password = filter_var(trim($_POST['password']));
// $confirmPassword = trim($_POST['confirmPassword']);

// if ($password !== $confirmPassword) {
// flash("register", "Passwords do not match.");
// redirect("../signup.php");
// }

// initalize data
$data = [
'name' => $firstName . ' ' . $lastName,
'contact_number' => $contactNumber,
'email' => $email,
'password' => password_hash($password, PASSWORD_DEFAULT),
'role' => 'user'
];

// validate the inputs before saving


if($this-> userModel-> registerUser($data)){
flash("register", "The account was created sucessfully!");
}else{
die("Something went wrong");
}
}
}


and this is my index php file for the routing:
<?php
require_once __DIR__ . '/Connection.php';
require_once __DIR__ . '/controllers/UserController.php';

$pdo = new Connection;
// $pdo = (new Connection())->pdo;
$controller = new UserController;

// routing for user registration
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['registerUser']))
{
$controller ->registerUser();
}
else {
echo "Error";
}
?>


However, it doesnt work and I don't understand what's going wrong.

I only have about 4 days left until we need to run it and do the testing 😭😭 thank you!!

https://redd.it/1l8vtek
@r_php
My first Laravel package, released during PHP’s 30th anniversary month 🐘🎉

🚀 Proud to introduce laravel‑setanjo — my first Laravel package, released during PHP’s 30th anniversary month 🐘🎉

Laravel Setanjo is a powerful, multi‑tenant settings manager for Laravel apps. Whether you're managing global configurations or tenant-specific preferences, Setanjo makes it simple — and it's perfect for A/B testing and feature flag control too.

Key Features
🏢 Multi‑Tenant Support: strict & polymorphic tenancy modes
🗃️ Global & Tenant Settings: handles both user‑scoped and global configs
Automatic Type Casting: booleans, integers, floats, arrays, objects
🔒 Optional Caching: pluggable cache store for faster access
🧪 A/B Testing & Feature Flags: toggle features per tenant or globally
Clean API: intuitive facade calls — Settings::set(), Settings::for($tenant)->get()
🔄 Tenant Validation + Queue Support: secure and scalable
🔍 Fully Tested: reliable across use cases

Built for PHP 8.2+ and Laravel 10+

If you find it useful, please give it a star!

🧡 Feedback, ideas, and contributions welcome → https://github.com/AHS12/laravel-setanjo

Happy 30 years, PHP! 🐘

#Laravel #PHP #PHP30 #OpenSource #WebDevelopment #A/BTesting #FeatureFlags #MultiTenant #SaaS


https://redd.it/1l9kd18
@r_php
Are there any PHP dependency containers which have support for package/module scoped services?

I know that there have been suggestions and RFCs for namespace scoped classes, package definitions, and other similar things within PHP, but I'm wondering if something like this has been implemented in userland through dependency injection.

The NestJS framework in JS implements module scoped services in a way that makes things fairly simple.

Each NestJS Module defines:

* **Providers**: Classes available for injection within the module's scope. These get registered in the module's service container and are private by default.
* **Exports**: Classes that other modules can access, but only if they explicitly import this module.
* **Imports**: Dependencies on other modules, giving access to their exported classes.

Modules can also be defined as global, which makes it available everywhere once imported by any module.

Here's what a simple app structure might look like:

```
AppModule
├─ OrmModule // Registers orm models
├─ UserModule
│ └─ OrmModule.forModels([User]) // Dynamic module
├─ AuthModule
│ ├─ UserModule
│ └─ JwtModule
└─ OrderModule
├─ OrmModule.forModels([Order, Product])
├─ UserModule
└─ AuthModule
```

This approach does a really good job at visualizing module dependencies while giving you module-scoped services. You can immediately see which modules depend on others, services are encapsulated by default preventing tight coupling, and the exports define exactly what each domain exposes to others.

Does anyone know of a PHP package that offers similar module scoped dependency injection? I've looked at standard PHP DI containers, but they don't provide this module level organization. Any suggestions would be appreciated!

https://redd.it/1l9tvoh
@r_php
Package Release Progressive JSON Streamer for PHP — inspired by Dan Abramov’s Progressive JSON → Laravel ready

Hey everyone,

I just released a small open-source package I built after watching Dan Abramov’s Progressive JSON video.
👉 youtube.com/watch/MaMQLNBZz64

The idea is to send a base JSON skeleton immediately, and stream placeholders progressively as your app resolves slower data (DB/API/etc).
→ Works great with React Suspense / Vue Suspense / dashboards / large APIs.

Laravel ready → works with response()->stream()
Vue / React friendly → tested with simple JS client
Supports nested placeholders → root.nested style
Breadth-first streaming (vs depth-first)

GitHub repo:
👉 https://github.com/egyjs/progressive-json-php

Would love to get your feedback — and especially curious if anyone sees other cool use cases inside Laravel apps.

Happy to answer any questions — cheers 🚀.

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