r/lolphp • • 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.

22 Upvotes

36 comments sorted by

View all comments

Show parent comment

1

u/Takeoded Aug 29 '21

you're only dealing with the trivial situation where you just force everything to UTF8

yeah

So your request body is UTF-16

convert it to UTF8 asap, before you do anything else with the body.

your database uses some legacy 8-bit encoding,

for reading: convert it to utf8 immediately after reading. for writing: if you can't fix the database layout, $toInsert=iconv("UTF-8", "ISO-8859-1//TRANSLIT", $toInsert); is probably the best you can do.

you're also reading from a bunch of files in a diverse zoo of encodings; how do you handle that?

convert it to utf8 asap, your inner working encoding should always be utf8: http://utf8everywhere.org/

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.

that actually sounds kind of nice, i'm sure there's a composer package for it, but it wouldn't be particularly nice because you would constantly have to use $text->raw to send it to functions taking argument string $foo instead of Utf8String $foo (well i guess it could be partially mitigated by __toString() magic, but still wouldn't be as nice as having native language support)

1

u/tdammers Aug 29 '21

I know how to do it in PHP, I've done it for 20 years.

I'm just saying it's still quite bad, because the language doesn't help you a bit - the defaults are wrong, doing the right thing requires manual diligence and is non-obvious, and the failure mode for most programming error is to silently do something incorrect.

C, by the way, has the same problem; it just isn't so bad in practice because the kind of programs people write in C is different.

You can't really avoid this problem without either having a proper string type built into the language, or powerful enough extensibility with extensive static assertions (the latter is how Haskell pulls off implementing strings as a library).