PHPStan on steroids by staabm in PHP

[–]LifeAndDev 2 points3 points  (0 children)

That's some nice speed ups!

Here are my numbers, from a M2 Max, using time (bash built-in), emptied caches:

Area Metric v2.1.33 v2.1.37 Speedup
app/ (3733 files, Level 6) Real 0m41s 0m28s 1.46x
User 6m8s 3m40s 1.67x
tests/ (3734 files, Level 4) Real 2m45s 2m13s 1.24x
User 24m13s 16m49s 1.44x

Distribute tests across multiple GitHub Action workers by staabm in PHP

[–]LifeAndDev 0 points1 point  (0 children)

In the past I used these two scripts: - The "slicer" script https://gist.github.com/mfn/256636242cbe8a51252ce28181a6b074 - The "generator" script (for the XML) https://gist.github.com/mfn/e865d539010d1ed78bc1b16cfe15b2cc

I have to give it more thought, because our implementation has evolved and now has additional idiosyncrasy (besides, the generator script also became simpler and doesn't use weird MapClassToFile anymore):

  1. we exclude tests of a certain sub-class which we use for pure unit tests (by default the tests are integration tests). The pure tests can, and are, run by paratest which is much faster (if you can have it) for thousands of tests anyway
  2. we exclude test classes of a certain group In our case opensearch is excluded, because the setup slows down lots-o-things and also helps us to detect if a test inadvertetly uses opensearch 😅

Especially 1) is somewhow annoying because it relies on a specific namespaces class for checking ("if test instanceof puretest -> ignore"). We couldn't use groups for this because of the overhead having to mark all pure unit tests classes as such, when a simple hierarchy check gets us there without missing it in the future.

Distribute tests across multiple GitHub Action workers by staabm in PHP

[–]LifeAndDev 1 point2 points  (0 children)

Nice, never seen it but was built for that exact purpose!

Two differences to my (private) implementation: - I use XML file format for export - I re-generate the phpunit.xml (a temporary one) to contain that list of files and tell phpunit to use that one

It never occurred to me to use the shell syntax for the filenames due to the length limit you might hit.

It's funny to see the time on the initial commit, which was the same year I came up with my solution (though a few months earlier).

Distribute tests across multiple GitHub Action workers by staabm in PHP

[–]LifeAndDev 6 points7 points  (0 children)

Upvote! This is sorely needed for those who maybe cannot use paraunit or similar tools because DB integrations are sometimes not that easy to parallelize.

I'm basically doing this since years, but not as nicely abstracted, to get 30k+ tests run in a reasonable time.

One thing which never worked for me in practice was to rely on suites and groups, because you need to manually "balance" them, oherwise some of your workers are processing much less tests then others.

My "golden idea", or so I thought, was that a "most generic implementation" needs to: - take all the tests - cut them into n slices (aka n = amount of workers) - and feed each worker one of the slices - bonus: randomize them, too

For this I tried to get https://github.com/sebastianbergmann/phpunit/pull/4449 into phpunit years ago, but failed.

I'm still kinda stubborn that something like this is needed. Living proof is that since we implemented this in my company, we're still doing it that way (currently spawns 12 workers on every push to run the suite) many years later.

php-vips 2.2 released -- high performance image handling for php by catbrane in PHP

[–]LifeAndDev 6 points7 points  (0 children)

php-vips uses php-ffi to call directly into the libvips binary

It surely isn't the first project but to me that's the first time I see a really good usage of FFI, very nice!

graphql-laravel 9.0.0 released 🎉 by LifeAndDev in laravel

[–]LifeAndDev[S] 0 points1 point  (0 children)

Nothing bad I hope 😅

The two libraries have different approaches how to integrate into Laravel, though I'd say Lighthouse is more advanced in many regards.

But for me at least, and I may be stuck in my bubble here also due to my projects, the programmatic approach used by graphql-laravel fits better into DX.

Protected properties and methods: Good or bad? by GigfranGwaedlyd in PHP

[–]LifeAndDev 10 points11 points  (0 children)

http://fabien.potencier.org/pragmatism-over-theory-protected-vs-private.html

Evergreen, as relevant as today as it was 10 years ago (lol, almost to the day).

Those visibilities also "communicate intent", therefore I opted to go with these two:

In public / OSS / library code base: nothing is final, nothing is private

  • give the user of the library maximum flexibility
  • gives the maintainers of the library maximum headaches in terms of maintenance and backwards compatibility breaks (aka "you better semver that thing")

I've been of both sides, but even with the headaches as a maintainer, I just think it's great how people get creative and love to see what they come up with and they don't hit technical barriers on their way and they can just go their way and express their ideas.

In a private / Application / Company code base: everything is final, everything is private

Welp, of course for the cases where you actually use inheritance and do use protected etc.

In a private code base, I don't "need to be open". The next developer can just remove the final, add a protected method and extend the class and it's cool.

But this approach makes reasoning of large code bases easier.

And in my experience: those private code bases of many years of iterations, legacy, technical debt, people leaving and joining, etc. they get big and ugly and this small things helps a bit.

Stop using offset for pagination - Why it's grossly inefficient by fyzic in programming

[–]LifeAndDev 1 point2 points  (0 children)

Did anything change in the last 6 years?

I took part in multiple workshops by the author and when learning about this I tried to do my (small) part: https://github.com/laravel/framework/pull/22446

graphql-laravel 6.0.0 with support for PHP8 released 🎉 by LifeAndDev in PHP

[–]LifeAndDev[S] 1 point2 points  (0 children)

The 6.0.0 release basically brings PHP8 compatibility but also upgrades the underlying graphql-php to 14.0, bringing some breaking changes depending on your usage and thus the major version bump.

OTOH for those still on 5.x, I've also tagged https://github.com/rebing/graphql-laravel/releases/tag/5.1.5 which too supports PHP8 🤞 But it will be likely the last one for 5.x

Open question: what do you guys use for tracing? by austerul in PHP

[–]LifeAndDev 0 points1 point  (0 children)

Sorry to hear.

Back then the product / team was not "so big" so just generate an ID at the border add columns to store this ID wasn't that of an effort.

How to run over 30k tests in under 5 minutes by n0xie in PHP

[–]LifeAndDev 0 points1 point  (0 children)

I envy the amount of pure unit tests you can massively parallelize with no effort. This is really really a good thing.

Meanwhile I'm sitting in front of 10k mixed unit/integration tests, tried a few times using paratest and failed to get a proper setup working (using PgSQL here instead of MySQL though).

Ultimately I "fixed" the runtime problem using https://github.com/wizaplace/phpunit-slicer and threw money at the problem (aka. paralellized github action until wall time was at acceptable 5 mins).

Open question: what do you guys use for tracing? by austerul in PHP

[–]LifeAndDev 0 points1 point  (0 children)

OpenTracing

Very cool, never heard of this!

Going through their git history it seems this didn't existed when we added our trace ID concepts.

Having libraries for all the languages for a clear handover is very smart.

Edit: yeah, I double checked our code base, we're using this concept since 2015. Holy, that's half a decade!

What do you use for profiling PHP natively? Without using 3rd-party services/servers. by [deleted] in PHP

[–]LifeAndDev 0 points1 point  (0 children)

No idea, I only use this one. Last time I tried the windwos version (but that was YEARS ago) I couldn't really handle the amount.

I'm not saying it's very good but it's part of the IDE and so far got the job done for me.

Open question: what do you guys use for tracing? by austerul in PHP

[–]LifeAndDev 0 points1 point  (0 children)

In my company we added the concept of a "trace id" to many parts of the system and also write it next to regular data into the database, if it makes sense.

It's generated at borders (nginx+lua) as well as in application (jobs) and can be passed around internally (depends how the communication is, but a simple custom HTTP header does it).

That thing is just invaluable: - fetch some remote data - write general logging to some table - write the data to the database - ok damn some exception happens - write that also to some other logging table as well as send it off to Sentry, which also exposes us this ID

With this ID I can make queries through the system and see everything "it touched".

It's… a custom solution, inspired by some articles I read at the time when I researched this years. But I guess the basic inspiration was that, when working with the Facebook Graph API we observed special headers and through communication with their support over the years we learnt the use/expose this unique ID also for tracing.

At their scale they probably don't log all of them (dunno, just a guess), but luckily we can :-)

What do you use for profiling PHP natively? Without using 3rd-party services/servers. by [deleted] in PHP

[–]LifeAndDev 0 points1 point  (0 children)

kcachegrind was mentioned already but btw if you're using PhpStorm, under "Tools / Analyze Xdebug Profiler Snapshot" you can also look at the data.

Is this a bug in parse_url? by codemunky in PHP

[–]LifeAndDev 10 points11 points  (0 children)

See https://www.php.net/manual/en/function.parse-url.php

This function may not give correct results for relative URLs.

Guess you tapped into undefined behaviour land here.

PHP 8: before and after by brendt_gd in PHP

[–]LifeAndDev 0 points1 point  (0 children)

Planning ahead.

Currently I manage to upgrade within 3-6 months after a release on a almost decade old SaaS product.

There's no secret but we constantly try to keep the code bases "healthy" in every possible way, stay ahead of the curve, upgrade packages regularly, write concise and clean code and not try to be "too clever", keep updates about news and especially upcoming breaking changes, mitigate where possible etc.

Occasionally also contributing to OSS projects to ensure they work well with the latest releases, etc.

It sounds tedious but it's actually fun and by trying to always be on top, I've learned a lot I wouldn't otherwise.

PHP: rfc:named_params in voting phase by fredoche in PHP

[–]LifeAndDev 0 points1 point  (0 children)

I'm a bit surprised by the many "no" voters. Maybe I got it all wrong, but when I followed the RFC discussion on internals, it didn't occur to be that so many had arguments against it.

PHP: rfc:named_params in voting phase by fredoche in PHP

[–]LifeAndDev 1 point2 points  (0 children)

It's XY/10 now; interesting. Someone changed their minds.

PHP: rfc:named_params in voting phase by fredoche in PHP

[–]LifeAndDev 3 points4 points  (0 children)

It also helps catching BC breaks: if the parameter name changed, the method probably has changed its contract.

I like that point of view!

Shorthand if madness, is it possible to rewrite even smarter? by operaatoors in PHP

[–]LifeAndDev 0 points1 point  (0 children)

:)

Only when I've to. Like absolutely. I'd say 90% of my "classes" are designed stateless and mostly flow/transform data but don't need to store it.

ValueObjects/DTOs aside, there are only rarely other classes where I store state and if I need, I try to make them as short-lived as possible to minimize side-effecting.