
Goro – An implementation of PHP written in Go - stp-ip
https://github.com/MagicalTux/goro
======
muglug
> PHP is a nice language but is having trouble keeping up with modern
> languages

It's only "having trouble" because it can't change its API from month to month
to match whatever's in vogue. A majority of the web still runs on some variant
of PHP, and that guarantees that it's not dying anytime soon.

More broadly, it seems the author wants to create a version of PHP that's not
focussed on web requests, which is sort of the entire point of PHP.

~~~
mholt
> a version of PHP that's not focussed on web requests, which is sort of the
> entire point of PHP.

But even for web requests it's terrible. Or at least, it was, last time I used
it years ago. Couldn't really do any long-running tasks in response to an HTTP
request, or load a single data set into memory to share among all the HTTP
requests over the lifetime of the server. (Maybe you could, but I couldn't
figure out how.)

I'm quite happy that I haven't touched PHP in years. As fun/cool as this
project is, there's nothing I miss from PHP that isn't present -- or even
better -- in Go.

~~~
nicoburns
PHP has gotten a lot better. New APIs have been added on top of features like
classes. And many of the worst of the older APIs have been deprecated.

It still works on the "new interpreter per request model". But that has
advantages in the multicore world: everything is thread-safe by default, and
will scale to N cores without any extra work (for shared state people tend to
use something like Redis).

It's by no means perfect. But if you stick to the modern bits and use one of
the nicer frameworks (like Laravel), then I think I'd prefer it over something
like Ruby.

~~~
debaserab2
> use one of the nicer frameworks (like Laravel)

Yikes

~~~
cityzen
And?

------
johnwheeler
Interesting. This is a repo from Mark Karpeles, the former MtGox CEO

~~~
waitwhatt
Hah. You can lose people hundreds of millions of dollars worth of assets and
because it is magic internet money and not real money, you are coding instead
of in jail.

~~~
viraptor
Are you advocating for debtors prisons? If someone losses money you gave them,
would you rather they were in prison, (living from your taxes) or working and
repaying?

Also if the bankruptcy proceeds as planned, nobody will lose real money. (Btc
sale so far covers all the fiat they owe and a bit more)

~~~
shawabawa3
I think he's advocating for prison time for serious fraud - around $450m of
assets stolen/lost through incompetence

~~~
jerguismi
The history of mtgox is not that simple and it is somewhat difficult to say
who actually was the guilty one. Maybe there was lots of incomptenece involved
but I'm pretty sure that also in a situation like that it might be so
difficult even think straight.

MtGox was actually developed by Jed McCaleb, and Karpeles (MagicalTux) later
bought the business from Jed. At the time of the sale the exchange already had
tons of issues and apparently missing 80k BTC. It was perfect timing for Jed,
who later started Ripple. For Karpeles the biggest mistake was buying the
business. I would consider the latter mistakes only a minor mistakes. I would
guess the codebase/security/etc was quite a horrible as well, can't really
blame MagicalTux for not managing to save that business.

[https://www.newsbtc.com/2016/05/22/mt-gox-a-new-
revelation-s...](https://www.newsbtc.com/2016/05/22/mt-gox-a-new-revelation-
surfaces/)

------
krapp
One of the most "hip to hate" languages implemented in one of the most "hip to
love" languages...

~~~
agumonkey
wait for js.rs

~~~
ChrisSD
You joke but that's very likely to happen eventually if it hasn't already. At
the very least I wouldn't be surprised if Mozilla made a prototype JS engine
in Rust.

~~~
mattdeboard
Yeah buddy. [https://servo.org/](https://servo.org/)

Also there is already amazing work for Rust and WASM
[https://rustwasm.github.io/book/](https://rustwasm.github.io/book/)

~~~
jayflux
Servo uses spidermonkey

~~~
mattdeboard
Oh, I see. Thanks. I assumed the JS engine was written in Rust!

~~~
earenndil
Spidermonkey will probably never get rewritten in rust, as the safety
guarantees would be precluded by JIT.

~~~
bpicolo
That's not entirely the case - there's definitely research / work being done
in this area.

[https://blog.mozilla.org/javascript/2017/10/20/holyjit-a-
new...](https://blog.mozilla.org/javascript/2017/10/20/holyjit-a-new-hope/)

[https://github.com/nbp/holyjit](https://github.com/nbp/holyjit)

------
TheDong
A perfect example of error handling in go in the wild:

[https://github.com/MagicalTux/goro/blob/3cb3dfe0eef910c03e41...](https://github.com/MagicalTux/goro/blob/3cb3dfe0eef910c03e415e68ca29d7928c14e68a/core/compile-
for.go#L117-L152)

More php interpreters is of course nice.

~~~
hpbd
I don't understand. I have a C background. What is wrong with that?

~~~
nkozyra
Probably the repetition of

if err != nil {}

You get used to that pretty quickly in Go, but it still looks messy to a lot
of people.

~~~
dymk
And so it's clear to others, this probably the worst possible way for a
language to go about implementing error handling (maybe aside from just not
having any mechanism outright and terminating).

But alas, those are the choices that the Go language made.

~~~
isodude
Is it really though? I've tried out Exceptions in most languages and Go's
error handling stuck out to me as the first one that is clear what it does,
which of course is the mantra of the language.

~~~
TheDong
Exceptions are a strawman.

Compare it to another modern language such as rust. Go does not have a stdlib
mechanism for converting error types into each other (akin to rust's Into), it
doesn't have the idea of mapping values together (akin to rust's carrier
operator which is basically like monad do syntax), it doesn't have a way to
create a list of errors by default (akin to 'cause' in rust), it doesn't have
a way to generate concrete error types for your functions (like the 'failures'
or 'error-chain' libraries in rust, which can't be written in go due to a lack
of macros and generics and sum types).

It doesn't have a way to match on all possible concrete error values (akin to
'match' in rust or other sum-type things) or to do thing slike '.and_then' or
'.map_err' or so on.

Go's error handling is downright insulting in a language that wasn't built at
the same time as c.

------
tyingq
_" Better caching of compiled code by allowing sharing of compiled or live
objects (classes, objects, etc) between running PHP scripts"_

I'm a little confused on this piece, as PHP does have a cross process opcache.
People also use things like apcu to share userspace things across processes
(uses mmap).

~~~
treve
I think the idea is for example creating an object in 1 PHP process, and
modify it in the second.

The point is there is no shared state in the running problem

~~~
tyingq
Well, it mentions classes, for example. The opcache handles that already,
cross process. For a live object, people tend to use apcu. It's not as nice as
a shared object across 2 couroutines, but it's reasonably fast because it's
using mmap and fairly fast serialization to share the object.

So, what they are proposing is helpful. But, they seem to be assuming that PHP
shares nothing across processes. That's just not true.

~~~
treve
I'm not sure what you're trying to argue. A shared server state is a
drastically different model from having the ability to access a key->value
store. Try sharing a socket for example.

~~~
tyingq
That would have been a better example than 'classes', yes.

------
hbcondo714
For C#, checkout PeachPie which allows you to run PHP applications on .NET
Core including WordPress - [https://www.peachpie.io/2017/02/wordpress-
announcement.html](https://www.peachpie.io/2017/02/wordpress-
announcement.html)

~~~
jchw
PeachPie is really interesting. I haven't had a chance to use it, but the most
fascinating bit to me is that it can _compile_ PHP to .NET. Could be a great
way to incrementally move legacy code if you like writing servers in .NET,
potentially. I do wonder how things like Wordpress extensions and dynamically
generated code work, though. phpBB, for example, generates PHP files at
runtime for its formatting engine (s9e TextFormatter, it's quite a nice
library.)

------
pippy
Why is mcrypt listed as a future extension? it's removed in the latest PHP
version and probably best to not even bother with

------
PunchTornado
> PHP is having trouble keeping up with modern language

which are these modern languages and which are the cases where it is not
keeping up?

IMO PHP is one of the languages where development is really quick and the
ecosystem is flourishing.

~~~
mattigames
A great way to look into the future of languages is checking how many people
is learning it now compared to the last few years, a great tool for that is
google trends and things don't look good for PHP:
[https://trends.google.com/trends/explore?date=all&geo=US&q=p...](https://trends.google.com/trends/explore?date=all&geo=US&q=php%20tutorial,python%20tutorial)

~~~
colecut
There is also this to consider

[https://haydenjames.io/80-percent-web-powered-by-
php/](https://haydenjames.io/80-percent-web-powered-by-php/)

~~~
The_Amp_Walrus
> Today, PHP is used by more than 80% of all the websites _whose server-side
> programming language we know_

I find it pretty annoying that they don't post stats on the websites that they
couldn't classify. I think it's likely that their survey suffers from some
level of survivorship bias: only websites that loudly announce their tech
stack get counted.

So, how do they know which programming language is being used by a server?
From [https://w3techs.com/faq](https://w3techs.com/faq), they look at:

\- HTML elements of web pages

\- Specific HTML tags, for example the generator meta tag

\- The URL structure of a site

\- HTTP headers, for example cookies

\- HTTP responses to specific requests, for example compression

I typically run Python / Django sites, and the only way, that you would know
I'm running Python is a few Django-specific security/auth cookies. _Maybe_
that stuff gets picked up by their crawler. If I was running another Python
web framework, like Flask, then you'd have no idea what kind of app server was
sitting behind NGINX.

------
azhenley
Any chance someone wants to do a benchmark to compare the performance of this
to other PHP implementations?

~~~
tmh88j
I'd rather see a simple web app made with this benchmarked against one made
with Phalcon. I know that's comparing apples to oranges given that this is an
implementation and Phalcon is a framework, but it would be interesting to see
if this approach is any faster than writing a framework from extensions in a
faster language

------
Aeolun
But... why?

If you are going to write a go program to run PHP to use go specific features,
why use PHP at all?

~~~
nkozyra
One common reason is to port/enable feature-specific legacy code without
having to drag along a standalone interpreter.

It can also be used as a common in-application scripting language.

------
jacob019
Can I run WordPress on it today?

~~~
mcrittenden
No:
[https://github.com/MagicalTux/goro/blob/master/README.md#tod...](https://github.com/MagicalTux/goro/blob/master/README.md#todo)

~~~
jacob019
pre-alpha, bummer. Over the years I've had quite a few friends and family ask
me to arrange hosting of their wordpress sites. Generally I refuse because
wordpress has a long history of security problems. An alternate interpreter
with sandboxed execution could solve a lot.

~~~
nkozyra
I don't see what it fixes. You're just replacing an interpreter and in all
likelihood bundling a web server.

PHP 7 is a pretty solid language. I don't like WordPress at all, but there's
so much cruft, legacy nonsense and plugin garbage that you won't win that
battle.

~~~
jacob019
well obviously we won't win the performance battle, and it may be impossible
to protect the database and user data, but sandboxed execution with a virtual
filesystem could protect the overall system, keep it from joining botnets and
sending spam, etc.

~~~
nkozyra
Ok, but think about how many other ways you could fix that by wrapping battle
tested interpreters.

------
cozzyd
Does it reproduce the ternary operator order "feature?"

------
tbrock
Maybe this one will free some memory once in a while.

------
rs86
Funny how so much is missing. I mean what does work?

~~~
merlincorey
Since the author is one of the MtGox folks, this comment is pretty hilarious,
possibly accidentally.

~~~
rs86
Yes, it was accidental. But I had a good laugh. Thanks

------
utam0k
Awesome.

------
EGreg
What I want to know is, can I just compile PHP under iOS and Android and run
it?

Why doesn’t PHP work out of the box on those systems if compiled?

------
Solar19
I don't like unnecessary layers. Interpreted languages waste silicon and
energy. I've heard startups justify using Ruby or PHP by saying "servers are
cheap", which is just a bad engineering mindset.

Instead of building PHP apps on a PHP platform built in Go, people should just
build apps in Go. Or in C++, D, Nim, F#, C#, or even Java 8 or 10 with that
new AOT compiler. (I think F# and C# can also be compiled in advance with
CoreRT, but even if they can't, they're a huge upgrade over any interpreted
language.)

I would mention Rust except that it's terrible. All popular programming
languages in our timeline are bad, and deter millions of smart people from the
profession. But Rust is extraordinarily bad and should be replaced.

~~~
untog
> I've heard startups justify using Ruby or PHP by saying "servers are cheap",
> which is just a bad engineering mindset.

But a sensible startup mindset. Use whatever setup allows you to get things up
and running the quickest. By the time you run into scaling problems brought
about by a choice to program in Ruby (if you ever do) you'll have a viable
product, and can transition pieces away as you see fit.

