
PH7 – An Embedded Implementation of PHP (C Library) - symisc_devel
https://github.com/symisc/PH7
======
munificent
This seems like madness to me. It's "PHP", so it inherits everything that's
bad about that language. But it's also incompatible with PHP, so you don't
even get the power of being able to reuse the world's existing PHP code and
expertise.

    
    
        * PH7 is case-sensitive unlike the standard PHP engine
        * Unlike the zend engine which passes arrays by copy, PH7 pass arrays by reference exactly like PHP5 does with objects (class instances).
    

I'm not saying the extensions and changes they've made aren't for the better,
but they mean this language is effectively _not_ PHP. And, if you're going to
use a language that's not PHP, why not use one that's significantly cleaner
and simpler?

~~~
Kiro
It's still great for embedded devices when your main language is PHP.

~~~
camus2
> when your main language is PHP.

There is your problem.If you cant learn anything else pretty sure you havent
the skills to program any "embedded device".

~~~
ANTSANTS
I'd normally agree, but "embedded device" in this situation means "network
router" (which are reasonably powerful computers in their own rights), and the
application is not mission critical with hard deadlines and strict memory
requirements, but just a web interface that is rarely active and can take as
long as it wants running in the background. It doesn't seem unreasonable to me
to set aside some portion of memory for the web interface, give the PH7
process low priority, and hire some PHP web devs that actually know what
they're doing to make the interface for them. More sense than letting the
firmware developers hack something together in C anyway.

~~~
geon
I'd say the better way would be to develop the entire GUI with static HTML +
JS files talking to the embedded device through a REST-ish interface.

That way you can get a clean separation of the front and back ends, and the
web developers get to work with exactly the tech they are used to.

~~~
ANTSANTS
I'm not a web developer, but that sounds pretty sane to me. However, the
important part of their decision, I'm guessing, was not so much the PHP part,
but the "get people who actually know about the web to do this for us."
Someone has to build the site either way, and I'm guessing the embedded
engineers they had working on it didn't really know how to go about that.

EDIT: Another possibility is that they already had PHP devs working on their
corporate site or whatever, and they wanted to use them instead of hiring
another team.

~~~
donut2d
I am a web developer and the static HTML + JS with a RESTful API sounds
excellent.

------
Touche
> gcc -W -Wall -O6 -o ph7_test ph7_intro.c ph7.c

Nice! I wish creating Lua executables were this easy. With Lua you have to
create a wrapper C file, use squishy to combine multiple lua files into one,
and finally a script to turn the lua script into a C byte array. I have a
boilerplate project that I use so that I just have to run `make`, that avoids
the need to ever touch C for the most part. But it would be nicer if luac and
luajit did this automatically.

~~~
unwind
On the other hand, the single-source engine is so large, GitHub won't display
it on the web. :/

~~~
symisc_devel
SQLite style: The amalgamation is a single C code file, that contains all C
code for the core. With one big unit, the compiler can perform several smart
optimizations that cannot be done if the source code was split between
different C files.

~~~
72deluxe
Also makes it dead easy to download and embed into projects! Hurray for single
source files.

------
kodablah
That is one big C file. Curious if you've ran against any of the Zend tests in
the original implementation [1][2]. I do not see anything on
[http://ph7.symisc.net/](http://ph7.symisc.net/).

1 - [https://github.com/php/php-
src/tree/master/tests](https://github.com/php/php-src/tree/master/tests) 2 -
[https://github.com/php/php-
src/tree/master/Zend/tests](https://github.com/php/php-
src/tree/master/Zend/tests)

------
frik
The developer have also two other interesting projects on their website:

* jx9 - programming language based on JSON (like Lua with a JS syntax): [http://jx9.symisc.net/](http://jx9.symisc.net/)

* unQLite - NoSQL database engine (like SQLite but NoSQL): [http://unqlite.org/](http://unqlite.org/)

~~~
edsiper2
Unqlite is very good, we use it as our main in-memory key/value store in Duda
I/O [[http://duda.io](http://duda.io)].

------
FigBug
I've been looking for something like this. Originally I had planned to do it
with Python, but Python only seems to allow one interpreter at a time.

Does anybody know if it's easy to make new functions available to PHP that
would call into the C main program?

It says "Built with more 470 function" how does that compare with standard
PHP? If I take some PHP I've previously written or a library, is it going to
run with minor modifications? Or is this a subset of PHP?

~~~
symisc_devel
Yes, most of the built-in functions (over 470) are foreign C/C++ functions
installed exactly using the same interface: ph7_create_function();

~~~
stevekemp
Yeah that was pretty nice to see.

My first thought on seeing this project was wondering how hard it would be to
hook up to nginx, or similar. I don't really "do" PHP, so I'd probably not
attempt it myself, but I get the feeling from having written nginx modules in
the past that this doesn't look too hard - the PH7 API seems decent enough.

~~~
frik
Interesting, please write a blog post if you investigate this. It could be
like OpenResty (Lua + Nginx): [http://openresty.org](http://openresty.org)

I am using HHVM (Facebook's HipHop PHP w/JIT) with Nginx. that works great...
but it requires a 64-bit server. So for smaller servers or embedded systems
Ph7 sounds interesting.

------
captainmuon
This is pretty cool. First I was wondering what for, but its great for their
use case (embedded devices). Why not use a language for the web interface the
developer is familiar with.

Unfortunately, they're a bit late. Nowadays it would probably be cooler to use
JS, if language popularity is the focus. Or maybe python.

(Aside: I learned web development in the good old LAMP times. My silly gut
feeling is still that PHP is pretty fast and flexible compared to Python which
seems slow (on the server), and JS which is way too slow and fragile. I know
it's completely backwards nowadays, but funny how what you've learned sticks.
When I hear "JS on a Arduino" I always think "yeah sure....", but it's
actually a clever idea, just like this.)

~~~
Kiro
Is it Python really slower than PHP? If you could notice the slowness it seems
like the difference would be pretty large.

~~~
camus2
> compared to Python which seems slow

This sentence doesnt mean anything. What Python task? What library ? what
framework ? on what server? with which version ? ect... I can say PHP is slow
too, just look at any PHP framework, lowest scores according to techempower
benchmarks :

[http://www.techempower.com/benchmarks/#section=data-r8&hw=ec...](http://www.techempower.com/benchmarks/#section=data-r8&hw=ec2&test=plaintext)

------
jacob019
Normally I wouldn't touch PHP due to the long history of security issues.
Would this do anything to improve it? Love the idea of an embeddable
interpreter.

~~~
andrewmwatson
you're right, RoR is WAY more secure...

~~~
BlackDeath3
What made you jump to RoR?

------
zalthor
Curious, what do people who work with embedded systems usually use to get a
web interface for their device? Routers, for as long as I can remember have
had a web UI though I'm not really sure what sort of a back end runs it.

~~~
up-n-atom
A few that I've come around and evaluated are

[https://wiki.strongswan.org/projects/strongswan/wiki/Libfast](https://wiki.strongswan.org/projects/strongswan/wiki/Libfast)
\+ [http://www.clearsilver.net/](http://www.clearsilver.net/)

[http://appwebserver.org/products/appweb/server-side-
javascri...](http://appwebserver.org/products/appweb/server-side-
javascript.html)

[http://duda.io/](http://duda.io/)

[http://luci.subsignal.org/](http://luci.subsignal.org/)

~~~
edsiper2
i would be interested into your evaluation of Duda I/O, let me know your
comments.

------
ausjke
For embedded device normally LUA is used, how does PH7 compare to LUA? as
PHP/LUA is normally used to provide web interface, how does PH7 do CGI?

------
angersock
Erm...how would people feel about having this as an available module for
Node.js?

No reason. ;)

~~~
jbeja
...

------
rlidwka
62022 lines of code in a single file... is that a joke? :)

------
elwell
Pretty cool, but why's it all in one .c file?

