9 ms·
PHP-Tokio – Use any async Rust library from PHP
- otikik 3y agoHe was a punk, she did ballet. What more can I say?
- JonathanBeuys 3y agoPHP really took the wrong turn with PHP 8. It introduced such drastic breaking changes, that probably a lot of systems which were previously perfectly serving their users will be abandoned. Projects that could have stayed on the internet and served their users just fine. It broke the order of parameters in join statements. It broke calling static functions without the need to declare them as static. It broke adding properties dynamicly to objects. It broke easy string handling for many functions where Null was rendered as an empty string. And these changes make PHP code more bloated. There is now no way around adding more declarations to your codebase than before. Some of these breakages had 30% votes against them, including the original author of PHP: https://wiki.php.net/rfc/deprecate_dynamic_properties https://wiki.php.net/rfc/deprecate_dynamic_properties The bar for breaking changes should be much higher. Python's update from version 2 to version 3 caused a lot of pain. But at least it made the code leaner. Allowing users to go from "a=float(b)/c" to "a=b/c" is a good thing. Forcing users to go from "function f()" to "static function f()" is a bad thing.
- pluc 3y agoHN when legacy PHP is involved: PHP was a bad idea! No real coders would use it! It needs dramatic changes! HN when modern PHP is involved: PHP8 was a bad idea! They shouldn't have gotten rid of the legacy stuff!
- ianhawes 3y agoJust don’t upgrade to PHP 8 then? All of those decisions were made for specific reasons. I’ve noticed anyone complaining about PHP 8 for legacy reasons was barely off of PHP 5.
- JonathanBeuys 3y agoYou can't let web software sit on a stack that does not get security updates. The last release of PHP 5 was less than 5 years ago. Javascript from 20 years ago still works fine. That's the way it should be.
- gog 3y agoIf you are upgrading your web software stack, why aren't you upgrading your web software?
- withinboredom 3y agoThere are services you can pay for that backport security fixes to old versions of php.
- danogentili 3y agoJavascript is a client-side language, you don't have control of the software stack, thus (ideally, if you want to) you have to write code to support every version, even a prehistoric chrome build from 2015 (be it directly or indirectly via transpiling and polyfills). PHP is not like that, like in every other language where you can control the entire environment, it evolves and things break, and that's the way it should be, that's why we have semantic versioning.
- ahofmann 3y ago
- pachico 3y agoEvery time I read "PHP" in a thread I think "Here we go again with the useless hate/love comments". Can we just agree on "PHP used to suck but it was very easy to work with, reason why it got traction. Things got better over the years and those that only saw the early years, rightfully only remember how much it sucked, while those that use modern versions see how much it has changed"?
- dividedbyzero 3y agoI think that ship has sailed for the time being. Too many of the older cohort have been traumatized back in the day, and those that came after will only know PHP from horrible ancient codebase fossils no one wants to touch with a long stick
- pindab0ter 3y agoThere are also a lot of companies and people working with modern PHP frameworks. I’ve never had the displeasure to work with code bases older than a couple of years. My experience with PHP/Laravel has been that Laravel is an awesome framework on what is nowadays a ‘decent enough’ language. For comparison, at least PHP has first party type support nowadays, whereas Rails does not.
- 29athrowaway 3y agoThe reason it got traction was that it was easy to get a Linux, MySQL, Apache and PHP installation and getting it to run. The documentation was easy to navigate as well. This is often an overlooked aspect of it. It was comparable to ASP which was also popular at the time.
- phpisthebest 3y ago>easy to get a Linux, MySQL, Apache and PHP Come on now, it is Linux, Apache, MySQL, and PHP === LAMP... it was more than just easy of getting a server going, it over all ease of development, PHP was MUCH easier to work with as a developer than ASP or Perl, or any of the other early web lang's
- fideloper 3y agoSeems really cool - I’d love to know more about how this works. Are there some c bindings or something that lets us call a rust program from php? It sounds like the actual async features come from Revolt so I’m not 100% sure where Rust fits in. Because the rust lib used is async as well, they’re compatible?
- danogentili 3y agoThe PHP <-> Rust bindings are provided by https://github.com/Nicelocal/ext-php-rs/ https://github.com/Nicelocal/ext-php-rs/ (our fork of https://github.com/davidcole1340/ext-php-rs https://github.com/davidcole1340/ext-php-rs with a bunch of UX improvements :). php-tokio's integrates the https://revolt.run https://revolt.run event loop with the https://tokio.rs https://tokio.rs event loop; async functionality is provided by the two event loops, in combination with PHP fibers through revolt's suspension API (I could've directly used the PHP Fiber API to provide coroutine suspension, but it was a tad easier with revolt's suspension API (https://revolt.run/fibers https://revolt.run/fibers), since it also handles the base case of suspension in the main fiber).
- joe_hoyle 3y agoI’m one of the few contributors to ext-php-rs. I’d be interested in contributing to your fork if you are planning to support your fork too. I think there’s a lot of QOL improvements to be made still and also adopting newer php features etc
- danogentili 3y agoThat would be awesome! Yes, I'm planning to support my fork of ext-php-rs, given that it will be heavily used by our mongodb driver. I've actually sent an email to David Cole, asking him to make a maintainer of the original repo, but he hasn't replied yet, feel free to send your MRs to our fork in the meantime!
- amne 3y ago[flagged]
- dtjohnnymonkey 3y agoI was playing with something like this a long time ago back when I was excited about NodeJS. I hooked up libuv to PHP and got https://github.com/dtjm/php-async https://github.com/dtjm/php-async which seemed to work in simple experiments.
- danogentili 3y agohttps://revolt.run https://revolt.run / https://amphp.org https://amphp.org does basically what you did, except with also a bunch of nicely designed async libraries for HTTP/MySQL/Postgres/etc, stackful coroutines (like goroutines) with fibers and integration not only with libuv, but also with libev, or with plain stream_select. php-tokio plugs into revolt, which in turn allows it to coexist with any async library based on or compatible with revolt (i.e. the entire amp ecosystem, PSL, reactphp, etc...).
- firefoxd 3y agoThe example isn't very good at showing what it does properly. An improvement would be to show the results for different delays, not 5 seconds for all 3 functions calls
- danogentili 3y agoI used the same delay because this way when running via CLI it's clearer that the requests are made asynchronously, because the "Got response" lines are printed at the same time after 5 seconds, not 5 seconds apart each; using varying delays removes this neat simultaneous effect.
- deleted 3y ago[deleted]