Live data from Hacker News

Moving from Go to PHP Again

dannyvankooten.com

191–200 of 371 posts

Re: Moving from Go to PHP Again

#191
post #187

Question : modern PHP is great for websites, but what are the solutions when you need to make some async work ? For example if I need to make few third party API calls in parallel ? With Laravel I resorted to using queues which feels like more complicated than it had to be (each worker takes up quite a bit of memory). Eventually I switched to SQS + Lambda + node.js. Is there any mature way to do async work in PHP ? I…

> For example if I need to make few third party API calls in parallel ?

There’s curl-multi[0] you can use for that purpose. Not as nice as promises/async/await, but it gets the job done for your example.

[0] https://secure.php.net/manual/en/function.curl-multi-exec.ph...

Re: Moving from Go to PHP Again

#192
post #187

Question : modern PHP is great for websites, but what are the solutions when you need to make some async work ? For example if I need to make few third party API calls in parallel ? With Laravel I resorted to using queues which feels like more complicated than it had to be (each worker takes up quite a bit of memory). Eventually I switched to SQS + Lambda + node.js. Is there any mature way to do async work in PHP ? I…

One easy way to do multiple http requests in parallel are the curl_muli functions: http://php.net/manual/en/function.curl-multi-init.php

Thanks, that's one solution if making multiple calls is needed. That was mostly an example though, for example if I wanted to run 3 functions in parallel, I don't find any "easy" and elegant way. Some libraries exist like amp, but it seems a bit heavy handed as the language itself doesn't have great tools for it https://github.com/amphp/amp

Re: Moving from Go to PHP Again

#193

Earlier quoted context omitted.

I'm not saying it's not possible I'm saying it really isn't convenient .

But the reason why it isn't convenient is because the consensus amongst Java programmers is that it's a bad idea. It wouldn't be difficult to build tooling around if one wished to - I think in this case, the fact that almost every language has migrated away from CGI-style routing is probably telling.

> But the reason why it isn't convenient is because the consensus amongst Java programmers is that it's a bad idea. It wouldn't be difficult to build tooling around if one wished to

That's part of the inconvenience though, one of the advantages of CGI was the low tooling requirements.

> I think in this case, the fact that almost every language has migrated away from CGI-style routing is probably telling.

I mean sure, but beyond not being a very good protocol CGI needs to execute the handler script on every connection, Java is not known for that being cheap.

Re: Moving from Go to PHP Again

#194

Any idea why PHP has such a bad reputation compared to other interpreted and dynamically-typed languages such as Python?

This may sound trivial but I dislike the aesthetics and ergonomics of typing PHP. In most dynamic languages user.name is 9 keystrokes, but in PHP $user->name is 13 keystrokes.

100% agree. The syntax of languages such as php, c++ and rust just look ugly af. The use of $ and :: piss me off the most

Re: Moving from Go to PHP Again

#195

Earlier quoted context omitted.

With PHP it is much easier to hit all of the above.

PHP is also easier to get started, easier to understand and easier to modify. So it's a trade off.

This also leads beginners to overestimate themselves, resulting in piles of live, insecure PHP code.

Just because it works, doesn't mean it's good or secure. And while it's very easy to see if something works or not, it's very hard to see if something is secure.

Re: Moving from Go to PHP Again

#196
post #73
post #13

Each PHP file is an endpoint. As opposed to having routers in code or client side SPA routing. PHP files can be deployed independently, swapped out or updated live. No building/compiling of the php files needed. A single layer as opposed to 'modern architecture' where there's client side back/front end layers, api layer, logic, validator, data access, and ORM layers. Can extend itself as it runs. For example Wordpres…

> Each PHP file is an endpoint. As opposed to having routers in code or client side SPA routing. Except in reality once you want to use non /whatever/file.php as urls - you're back to implementing a router > PHP files can be deployed independently, swapped out or updated live. Intuitive, simple, powerful. Can be as easy as editing a php file in notepad and dropping it on a ftp server. Deployed. Except in reality, you…

1. lock in to a specific platform with limited visibility tools and a dependency on a 3rd party when shit doesn't work

The logging analysis tools are excellent and it’s quite easy to tie your lambda logging to whatever tool you are using.

As far as “lock-in”, there is an Amazon provided framework in every supported language to just add a proxy that allows you to use your standard framework (Node/Express C#/ASP.Net, etc) and you cab deploy to Lambda or your traditional web server with no code changes.

2. when functions change you run into function incompatibility chaos and no smart way to handle that mess

What???

3. the "scalability" win is a lie, it's just deferred to whatever data storage service you are using - which ends up blowing up because while serverless scales, the db doesn't

Serverless Aurora (Mysql) and DynamoDB both have autoscaling. You can also auto scale Read Replicas fast with traditional Aurora.

4. addendum to 3, the statelessness of lambda means you can not use local caches to increase your throughput - increasing your hardware requirement

Again not true, if you are calling an endpoint frequently, the instance stays warm for up to around 15 minutes and can maintain state.

Re: Moving from Go to PHP Again

#197

Earlier quoted context omitted.

>Amazon lambda may have more in common with PHP in terms of discreet deployable units of functionality. What's old is new again. This doesn’t seem to be a language choice problem, it seems to be a monolith problem, where PHP simply managed to avoid some of the traditional monolith issues by design. Your CD pipelines in any micro service architecture should solve these problems, whether it’s using FaaS or containers,…

>> PHP simply managed to avoid some of the traditional monolith issues by design No - it didn't. PHP up to this day is a spaghetti mess it had always been.

Being able to extend or replace modules easily (and especially online) is something that's challenging in monoliths. The design of PHP avoids this issue. I'm not really making any other statements about the quality of the language here.

Re: Moving from Go to PHP Again

#198
post #192

Earlier quoted context omitted.

One easy way to do multiple http requests in parallel are the curl_muli functions: http://php.net/manual/en/function.curl-multi-init.php

Thanks, that's one solution if making multiple calls is needed. That was mostly an example though, for example if I wanted to run 3 functions in parallel, I don't find any "easy" and elegant way. Some libraries exist like amp, but it seems a bit heavy handed as the language itself doesn't have great tools for it https://github.com/amphp/amp

Why do you want to run 3 functions in parallel?

Re: Moving from Go to PHP Again

#199
post #174

Earlier quoted context omitted.

I'm curious, what is painful about it? I came to Go from mainly C++, Java, and Python background, and I feel like it's the best of all 3 (to me). It's compiled and really fast (like C++), it has a great set of libraries and community interaction/support (like Java), and it has simple syntax that is clear and quick to understand (like Python). It's not a perfect language (nothing can ever be), but it's become my favor…

I talked with a few people who wrote Go servers and while they loved almost everything about the language and ecosystem, they hates the missing generics so much, they still switched to other languages later. Writing code-generators for everything wasn't fun.

I don't miss generics in Go and I have used generics in C++ a good deal. I think the whole generics argument against Go is largely parroted by people who may not even know what generics even are. C doesn't have Generics either. It's doing OK.

Re: Moving from Go to PHP Again

#200

In all seriousness... doees PHP have C# envy? With all of the stuff that has been put into PHP7 (like typed returns and typed arguments) and stuff being proposed (like annotations), PHP isn't that far off from being a interpreted brother of C#.

Better than the Java envy it had in the past.
Post reply on HN