/r/PHP

Photograph via snooOG

Share and discover the latest news about the PHP ecosystem and its community.

Please respect r/php's rules.

Please follow the rules

Releases: Current Releases, Windows Releases, Old Releases

Contribute to the PHP Documentation

Related subreddits: CSS, JavaScript, Web Design, Wordpress, WebDev


/r/PHP is not a support subreddit. Please visit /r/phphelp for help, or visit StackOverflow.

/r/PHP

179,624 Subscribers

100

Coming back to PHP after years lost in Node

As the title says.. I started programming back with PHP 4 as my first experience to coding.. Left when it PHP 7 was on the horizon. Now with the incredible mess that's called NextJS, Remix, React and what have you not I want to go back to an ecosystem that just works and does not constantly put me in pain.

I was working for an agency where we used Symfony 3.X at the end of my PHP career, and I played around with Laravel at home back then.

What are the "trendy" or just "reliable" frameworks in the PHP world and what do people use these days that offer all the amenities like queues, mailing, db access, payment handling (mainly using Stripe) for building smaller web apps / SaaS products? Still Laravel?

66 Comments
2025/02/03
13:05 UTC

6

Weekly help thread

Hey there!

This subreddit isn't meant for help threads, though there's one exception to the rule: in this thread you can ask anything you want PHP related, someone will probably be able to help you out!

0 Comments
2025/02/03
07:00 UTC

0

Need to search through imported data, but not sure about the method…

I’m working on a script that takes in data for a string search from external files. The data is stored in an internal data structure for fast searching then the useful data is stored in a db.

My question is if how much data should I import before searching through it?

Realistically, with the volume of data I need to search through, I could import for days, but is there an upper limit the data I can import? Or should I just setup my own arbitrary limit of how much to import before searching through it?

Thanks for any info!

24 Comments
2025/02/01
17:01 UTC

47

What are some real-life use cases of ReactPHP?

I have known about it for a while, I just did not think I need it. But lately I have been trying to get into it more and I need some inspiration, I need some ideas of what to try out, maybe I do have use cases for it, just did not occur to me.

So, the people who are using ReactPHP, what are you using it for?

33 Comments
2025/01/31
11:37 UTC

17

library review

Hey there! I'm a junior developer working on a PhpOffice/PhpSpreadsheet wrapper, experimenting with method chaining and closures to make styling and formatting more intuitive. Right now, the library has limited functionalities but I’m hoping to refine and expand it over time as it will be for my personal use. I’d love some feedback on its structure, readability, and best practices—are there any pitfalls I should watch out for or ways to make it more flexible? Let me know what you think!

This is my github repo. Thank you in advance!

22 Comments
2025/01/31
04:46 UTC

25

Is XAMPP enough for local development?

I’m a beginner and creating a shopping website using XAMPP but some people tell me to use Docker or some things like that but what’s the difference between these? You can just simply install Apache, PHP and MySQL all at once with XAMPP but is it not good?

75 Comments
2025/01/30
23:49 UTC

16

Laravel + TimescaleDB: Cross-pollinating ideas between PHP and Ruby ecosystems

Hey PHP/Laravel community! 👋

I'm a Rubyist working on improving TimescaleDB support across different language ecosystems. I recently came across this impressive Laravel implementation (https://github.com/tpetry/laravel-postgresql-enhanced) and, while I'm not a PHP developer, I'm amazed by how clean the API looks:

Schema::create('visits', function (Blueprint $table) {
// ... table definition ...
$table->timescale(
new CreateHypertable('created_at', '1 day'),
new CreateReorderPolicyByIndex('website_id', 'created_at'),
new EnableCompression(segmentBy: 'website_id'),
new CreateCompressionPolicy('3 days'),
new CreateRetentionPolicy('1 year'),
new EnableChunkSkipping('id'),
); ...

I'd love to hear from Laravel developers who have used this package:

  • - How's your experience with the API design?
  • - Are there any features you wish were implemented differently?
  • - For those using TimescaleDB in production, what additional features would you like to see?

As a maintainer of the TimescaleDB Ruby gem, I'm particularly interested in cross-pollinating ideas between ecosystems. TimescaleDB is actively looking to support and promote community projects like this through co-marketing opportunities - if you're building something cool with TimescaleDB or have interesting use cases to share, they're eager to help spread the word.

Looking forward to learning from your experiences and potentially bringing some of these ideas back to the Ruby ecosystem!

6 Comments
2025/01/30
19:43 UTC

9

Best way to curl a long running endpoint without waiting for response? (8.2)

Small bit of context:

I have a mobile app thats used by field based team members to complete “jobs” as they go about their day.

Currently, when they complete a job, the API will mark that job as complete, then run a whole load of other business logic to create an invoice, send notifications, take payments etc etc before returning a 200 to the app.

Because of flaky mobile service, that call can on occasion take much more time than I’d like, and aside from marking the job as complete (to update the app) none of the rest of that business logic is critical to the field user and can be done separately / asynchronously.

What I’d like to do:

Have the apps call /jobs/id/complete

Which is a quick call to update the job as complete and let the app carry on to the next job.

Then that endpoint to internally run something like

/jobs/id/invoice

Which will handle everything else but make endpoint /complete NOT wait for the result of that before returning its data to the app.

Anything that goes wrong payment wise with /invoice is handled by webhooks, field users don’t need to know whether the invoice was created successfully, or whether the payment failed, that’ll get picked up elsewhere.

Is there an accepted way to achieve this / is this even possible to minimise the response time of the basic request and let everything else happen behind the scenes

23 Comments
2025/01/30
18:49 UTC

3

How would you solve robust unique hash insertion?

Hello, there is one thing that scratches my mind. I would like to insert unique hash to a DB table column. I'm generating the hash with php bin2hex(random_bytes(32)) in while loop that ensures the hash does not exist in the DB column If it does, it gets regenerated.

Next I'm inserting the new hash to the DB column.

But there is a catch. If some other user is concurrently generating the hash as well, there is small chance that the hash would not be unique at the point of insertion.

I don't think transactions would save me there as the hash is generated by PHP.

22 Comments
2025/01/30
12:48 UTC

0

async php8

php8 fibers are stable?
can use it as nodejs replacement for async stuff? worth it?

18 Comments
2025/01/30
12:16 UTC

1

PHP Generator for MySQL (can't find)

Does anybody know where I can get a copy of PHP Generator for MySQL?

sqlmaestro.com has been offline for a few days now.

Here's an archive that shows the page where I would have downloaded it from but the app download is behind a login that will not work in an archive
https://www.sqlmaestro.com/products/mysql/phpgenerator/download

Thanks!

EDIT: they are back online 😀

2 Comments
2025/01/30
07:56 UTC

17

PHP interview question

I was asked this question in a PHP interview today. I don't understand, Google doesn't seem to have an answer either. Can anyone explain what this question means, or was intended to mean?

How can you create and declare the handler inside a single method call?
39 Comments
2025/01/29
20:20 UTC

0

Please critic this code

I have some comments on this code, but don’t want to lead in any way. I’ve been asked to review a Laravel project that was built by 2-3 senior developers. The first function I looked at had these lines of code in the login function. Let me know what you think. Requires some SQL knowledge too

$credentials = $request->only(['password']); $user = User::query() ->where('email', 'ILIKE', $request->email) ->first(); $credentials['email'] = $user->email ?? $request->email;

Thank you!

26 Comments
2025/01/29
18:15 UTC

11

PHPStreamServer: introduce Symfony integration!

I’m glad to announce the latest release of PHPStreamServer, the asynchronous application server for PHP applications—written entirely in PHP!

This update brings a new feature: Symfony integration! Now, you can easily run Symfony application with PHPStreamServer.

How to Get Started with Symfony:

  1. Run composer require phpstreamserver/symfony
  2. Start the server with bin/phpss start

That’s it! Your Symfony application is now up and running with PHPStreamServer. 🚀

For advanced configuration and integration with Monolog, check out the documentation page.

📖 GitHub Repository: https://github.com/phpstreamserver/phpstreamserver

📚 Documentation: https://phpstreamserver.dev

What is PHPStreamServer?

PHPStreamServer is a high-performance, event-loop-based application server and supervisor for PHP, written in PHP, built on the powerful AMPHP ecosystem and powered by the Revolt event loop. It brings asynchronous capabilities to your PHP applications, making them faster and more efficient. With PHPStreamServer, you can replace traditional setups for running PHP applications like nginx, php-fpm, cron, and supervisor. By running your applications in an always-in-memory model, PHPStreamServer eliminates the overhead of starting processes for every request, delivering a significant performance boost. The best part? No external services or third-party binaries are needed—just install it via Composer, and you’re ready to go!

7 Comments
2025/01/29
15:07 UTC

0

Why is PHP hated?

I've heard many people here in Colombia that not only don't like it but also talk shit about it. Why is that? I personally love it

59 Comments
2025/01/29
13:45 UTC

0

[QUESTION] How to build a Polylith in PHP

Hey there!

This will sound awkward and convoluted

I am trying to use port / use the polylith architecture in PHP (using the Python project as an example)
And I can't figure out how I would do the deployment process in PHP / what the equivalent is

The creator of the repo explains how project building works: https://www.youtube.com/watch?v=3w2ffHZb6gc

The main goal for now is to get a simple website up and running with an index and some post / get functionality

Is this subreddit the wrong place to ask about this?

11 Comments
2025/01/29
08:55 UTC

16

Is there any package/service that exists to backport a PHP codebase?

Hi everyone :) I was wondering if there was any existing package/service that has the ability to backport a PHP codebase (i.e. codebase that uses PHP 8.3 features) to be compatible with an older PHP version (i.e. PHP 7).

Basically, I'm looking for the inverse of what Laravel Shift does, but for any PHP codebase (instead of just Laravel).

Example use case: backport a package that requires PHP 8.3+ to be compatible with the current PHP version used by a given project.

Thanks in advance :)

P.S. I'm not looking for "just update your PHP version" comments. In my current scenario, it's a very big legacy repo that is not customer facing and other repos (that are customer facing) are being updated in priority. The time will come, but it's not now.

4 Comments
2025/01/29
02:12 UTC

0

Is there anything similar to Directus in php?

Hi guys, anyone knows a backend as service similar to Directus but made in php? The version 8 was in php, then they decided to move to laravel (but unfortunately choosed express instead)

12 Comments
2025/01/28
22:09 UTC

8

Any good blogs, articles or videos about event sourcing and projections?

Hello,

I have been reading and watching videos about event sourcing. The theory is clear to me but most of the times people do not go into the details of the thing.

I found this article which is awesome, and I wonder if there other similar articles or even videos out there.

Specifically I want to figure out how to handle rebuilding projections while production is up and running.

5 Comments
2025/01/28
14:59 UTC

1

Persistent data?

When php runs in long-lived service processes, like under php_fpm or Apache, we can use persistent database connections to sidestep the overhead of opening a new connection for every page view. Helpful in high-traffic web apps.

Is there a way for an ordinary php program (not an extension) to use that same persistence? Some global that survives the start of a new page view?

Edit a lot of folks have offered the advice don’t do that. I understand.

It doesn’t seem like there’s any way to reuse any data between uses of long lived php worker processes. I asked because I was hoping to create a SQLite3 object with some prepared statements, and reuse it. Guess not.

All this is in aid of a WordPress plugin to crank up performance and reduce server power consumption. https://wordpress.org/plugins/sqlite-object-cache/ It works well enough reopening SQLite for every page view, so I’ll keep doing that unless somebody has a better idea.

26 Comments
2025/01/28
14:32 UTC

51

Tinkerpad: a lightweight, free and open-source PHP playground

Hi everyone!

I'm launching the beta of my newest open source project, Tinkerpad. It is a lightweight and free PHP playground that you can use to run and test code on your projects.

You can run code on local projects, remotely via SSH or using Docker containers!

Some other features are:

  • Code benchmarking with Memory Usage and Run time.
  • Save favorite code snippets for later use.
  • Up to 100 code snippets history
  • Autocomplete using PHPActor language server
  • Theme customization

You can download the latest release and check out the code on our repository on Github.

Hope you all like it!

22 Comments
2025/01/27
21:30 UTC

2

I created a Laravel 11 sandbox with a SQLite database.

https://sandbox.ws/en/laravel-sandbox

Maybe it will be useful for someone.

You can test eloquent builder scripts, model relationships, collections, etc. Share your scripts (public/anonymous) or embed them in an iframe to demonstrate your cases on other sites.

3 Comments
2025/01/27
17:13 UTC

14

How to handle E_NOTICE in unserialize()

I'm looking for a smart way to handle or prevent unserialize() errors. Currently, I'm using set\_error\_handler(), but I don't like this solution.

My current code is:

$var = []; // default value
if ($serialized) { 
  set_error_handler(function() {}, E_NOTICE);
  $var = unserialize($serialized);
  if ($var === false) { // unserialized failed
    $var = [];
  }
  restore_error_handler();
}

Unfortunately, sometimes $serialized contains a string that is not a serialized php string, so I need to develop a nice solution.

Any ideas? (btw. I know about '@' - I'm looking for something else)

18 Comments
2025/01/27
16:52 UTC

Back To Top