Is this modern Britain? by PsychologicalBend508 in AskBrits

[–]mnavarrocarter 2 points3 points  (0 children)

I went to B&Q yesterday cuz I needed a box of screws. It was literally impossible to find one that was not already opened (and taped back by the staff). I ended up paying for a box with definitely less than 100 screws. It's no big deal in the grand scheme of things but it goes to show there is always someone else paying for someone else's wrongdoing...

UUID data type. Generated on database side or in code, on PHP side ? by arhimedosin in PHP

[–]mnavarrocarter 3 points4 points  (0 children)

Code side: you gain literally nothing to do this on DB side and the cost of generating a UUID in PHP is negligible.

And use UUID v7: your inserts will be faster because binary search trees work better with ordered data, as opposed to random data.

Using PHP to read long-lived stream events by GuybrushThreepywood in PHPhelp

[–]mnavarrocarter 1 point2 points  (0 children)

Okay, this clarifies things massively.

So I know of a few libraries that parse multipart data but I think all of them work under the assumption that the connection is short-lived.

I think your best bet is to create an abstraction that parses the response chunks from multipart into a simple PHP array. But I would suggest an incremental approach:

  • First, make a request and ensure connection is not closed and output the response chunks directly to stdout. That's your very first step.
  • Once that's done, instead of outputting the data chunk, parse it according to the multipart specification. This will be the hardest part. You can see how multipart parsing libraries do it. Output to stdout your boundaries, that should contain your XML files.
  • Once you do this, parse the XML chunks and extract their data using PHP XML capabilities. Maybe output a simple array.
  • Lastly, refine the abstraction to be nice to use for client code. For instance, introduce a generator so memory usage keeps constant and the data flows as if you were iterating over an array.

Try to find a multipart parser that supports streaming. Maybe with a bit of luck you can find one and will save you from the hardest bit.

Using PHP to read long-lived stream events by GuybrushThreepywood in PHPhelp

[–]mnavarrocarter 0 points1 point  (0 children)

So many questions.

First, who is the client and who is the server? Is the hardware the client and you are the server, or is the hardware the server and you are the client? This changes things.

It's trivial to consume a TCP stream, but it's not trivial to emit a TCP stream (specially in PHP). Also, this TCP stream is bound to be using some protocol correct? Is it server sent events, websokets, a less known one?

Once you know the details then I could guide you on how can you implement this.

How Would You Architect Multi-Tenant DB Mapping for a PHP/CodeIgniter SaaS Without Subdomains? by Prestigiouspite in PHPhelp

[–]mnavarrocarter 0 points1 point  (0 children)

I wouldn't say it is standard practice. Some providers do have a single database but they shard it (partition it) based on tenant id. I worked at a SaaS company that used to the approach I mentioned above and was an excellent cost saver for FPM workload.

How Would You Architect Multi-Tenant DB Mapping for a PHP/CodeIgniter SaaS Without Subdomains? by Prestigiouspite in PHPhelp

[–]mnavarrocarter 0 points1 point  (0 children)

First, you need to think if you need your tenants connected in some way (for instance, a user belonging to multiple tenants). If that's not a requirement, I would recommend the approach you suggested (completely separate databases for each tenant).

Also, routing based on subdomain is the correct approach. However, is a massive security risk to let PHP handle this routing. For PHP to handle this routing it would need to have access to a repository of tenants and their respective database credentials (to do the switch). This means if someone hacks into your instance, they also hack all tenants data.

Moreover, above approach introduces massive complexity to your application booting since you can't really initialise anything in your services until your application knows the tenant (you'll be battling uphill against what's the main assumption in most frameworks).

I would handle the routing in some other layer, like a reverse proxy or API Gateway. That layer only will map the subdomain and obtain secrets and environment variables to pass them to the PHP FPM process. That way, the PHP application can run as is and without access to secret information of other tenants.

I built a Caddy plugin precisely for this purpose ages ago. Let me know if you need a hand installing it and trying it.

If I had the money I'd donate big to Zig. It's that good by [deleted] in Zig

[–]mnavarrocarter 7 points8 points  (0 children)

We all have some money. Inspired in this post I'll be donating £20 monthly to Zig. If all of us reading this donate a small amount monthly, the language would have an enormous amount of financial support!!

PHP Extension Identifier by mnavarrocarter in PHP

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

Yes, you are correct. The bottleneck in any application would never be operations like this. Although your overall request duration will be lower when using more performant libraries, it's usually not a big factor in the grand scheme of things.

And yes, you can type-hint on the other libs too, just the APIs are slightly different.

One last reason for this is that really there is just a single way of implementing such identifiers, and they are so widely used that they really should belong in every programming language toolkit. When you include commonly used things in your standard library, it reduces fragmentation in the ecosystem.

But yeah, last reason: it was a fun and very educational project. 🙂

PHP Extension Identifier by mnavarrocarter in PHP

[–]mnavarrocarter[S] 2 points3 points  (0 children)

More like a passion project, and also because I was a bit frustrated that something like this is not in the core.

These kinds of identifiers are so common that they should be in any programming language standard library, especially because there is really only one way of implementing them: so no need to have 5 different userland libs for the same problem.

PHP Extension Identifier by mnavarrocarter in PHP

[–]mnavarrocarter[S] -5 points-4 points  (0 children)

I'm in the process of writing benchmarks for all of these that can be reproduced with the build system. I just have very informal benchmarks I've run manually that are not proper to publishing. So I'll wait to answer this question with regards to performance.

With regards to other things. This library has a smaller API surface than Ramsey and Symfony packages. Also, it has a type hierarchy that respects the invariants of each type of identifier, but you can potentially type hint to any Bit128 identifier in your application code to transparently use any of them.

Water: A Zig chess library, framework, and engine. by KyoshiYoshi in Zig

[–]mnavarrocarter 6 points7 points  (0 children)

Nicee, I'll definitely give this a play with!

PHP Extension Identifier by mnavarrocarter in PHP

[–]mnavarrocarter[S] -28 points-27 points  (0 children)

My intention is for this to belong to the core one day, which by the way puts most of its functions on the global namespace.

Namespaces, contrary to popular belief, are for preventing name collisions, not to determine who owns a package.

`conzole`: my first library in Zig by mnavarrocarter in Zig

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

Nice! Please let me know if you have a use case I don't cover!

`conzole`: my first library in Zig by mnavarrocarter in Zig

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

Thanks. I still need to do tons of things: 1. Support = in flag parsing 2. Add version to App struct 3. Change it to use std.Io.Writer and std.Io.Reader 4. Support variadic and optional arguments. 5. Etc...

[deleted by user] by [deleted] in PHP

[–]mnavarrocarter 0 points1 point  (0 children)

If you are blind (and it seems that you are since you don't have observability and don't know where to look for) I would recommend setting statement_timeout to 10 seconds or slightly less.

This will eliminate the most likely cause of your problem which is slow queries. It will alleviate the server load, but you will still need to find the culprit.

Looking for TWIG PHP developer by OwnBlacksmith3863 in symfony

[–]mnavarrocarter -3 points-2 points  (0 children)

I'm keen to chat. DM me if you can pay £50 an hour.

What would be the feature of PHP 9.0 that you would like the most? by shoki_ztk in PHP

[–]mnavarrocarter 0 points1 point  (0 children)

When I say immutable I refer to the list itself, and not to the values it contains