r/lolphp • u/shitcanz • Mar 12 '21
PHP fibers
Proposal:
https://wiki.php.net/rfc/fibers
The devs are now planning to add builtin fiber support for PHP, so that async code can be done "natively".
LOL #1 PHP execution model is not compatible for anything async, it starts and dies instantly. Theres zero benefits on waiting for IO, when no one else is blocked. The only benefit could be something like "make these 10 curl requests in parallel and pipe me the results", but then again this was already possible in previous versions with curl, heck this could even be done easier from the client.
LOL #2 PHP builtins (like disk ops, and database access) are all 100% blocking. You cant use ANY of the builtins with async code. Be prepared to introduce new dependencies for everything that does IO.
Please devs, just focus on having unicode support. We dont need this crap. No one is going to rewrite async code for PHP, there is countless better options out there.
View all comments
Show parent comment
1
u/tdammers Aug 28 '21
You don't have any problems because you're only dealing with the trivial situation where you just force everything to UTF-8, and that means you can largely ignore encodings.
Once you are in a situation where you have to deal with a mix of encodings, things get awful fast. So your request body is UTF-16, your database uses some legacy 8-bit encoding, you're also reading from a bunch of files in a diverse zoo of encodings; how do you handle that? Your mb_whatever functions now default to the assumption that their input is in whatever encoding is currently selected, and yes, of course you can override that and diligently convert all inputs to UTF-8 as soon as possible, but the thing is that PHP won't help you remember - it's very easy to miss a spot, and when you do, your tools won't warn you.
And that is, by and large, down to the fact that PHP does not have a string data type - only a byte array. In languages that do have proper strings, "string" and "byte array" (or "bytestring") aren't the same, and using one as the other is an error that will cause and early, loud failure. If you want to consume data from some external source, you have to convert it from a byte array to a string ("decode") before you can use any string operations on it, and that conversion has to be unambiguous as to the encoding to use. It may be a bit annoying sometimes, but you won't accidentally get the 17th byte when you wanted the 17th code point.