News for hackers. Stuff that matters.
Re:PH7 – An Embedded Implementation of PHP (C Library) by munificent on Wednesday February 19, 2014 @12:44PM (#7264867)
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?
Re:PH7 – An Embedded Implementation of PHP (C Library) by Kiro on Wednesday February 19, 2014 @01:29PM (#7265184)
It's still great for embedded devices when your main language is PHP.
Re:PH7 – An Embedded Implementation of PHP (C Library) by camus2 on Wednesday February 19, 2014 @01:42PM (#7265283)
> 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".

Re:PH7 – An Embedded Implementation of PHP (C Library) by ANTSANTS on Wednesday February 19, 2014 @01:58PM (#7265394)
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.
Re:PH7 – An Embedded Implementation of PHP (C Library) by geon on Wednesday February 19, 2014 @05:18PM (#7266732)
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.

Re:PH7 – An Embedded Implementation of PHP (C Library) by ANTSANTS on Wednesday February 19, 2014 @06:06PM (#7267232)
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.

Re:PH7 – An Embedded Implementation of PHP (C Library) by donut2d on Wednesday February 19, 2014 @07:29PM (#7267817)
I am a web developer and the static HTML + JS with a RESTful API sounds excellent.
Re:PH7 – An Embedded Implementation of PHP (C Library) by nly on Wednesday February 19, 2014 @10:19PM (#7268604)
This is exactly what LuCI does on OpenWRT, except they use Lua, which is a sane language designed for embedded environments.
Re:PH7 – An Embedded Implementation of PHP (C Library) by a-nom-a-ly on Wednesday February 19, 2014 @02:29PM (#7265636)
> If you cant learn anything else pretty sure you havent the skills to program any "embedded device".

How did you arrive at this conclusion?

Re:PH7 – An Embedded Implementation of PHP (C Library) by TheZenPsycho on Wednesday February 19, 2014 @04:01PM (#7266193)
it's obvious isn't it? it's like "if you can't learn calculous I'm pretty sure you haven't the skills to do rocket propulsion calculations"

Someone with only one language or a "main language" is someone who just simply has a lower level of skill than is needed for embedded programming- which requires lots of different skills and languages. Being able to learn more than one thing is a prerequisite.

Re:PH7 – An Embedded Implementation of PHP (C Library) by Kiro on Thursday February 20, 2014 @06:38AM (#7270254)
So if you work at company with a PHP stack (meaning your main language will obviously be PHP) you can't learn anything else?
Re:PH7 – An Embedded Implementation of PHP (C Library) by TheZenPsycho on Thursday February 20, 2014 @04:16PM (#7273661)
if your natural response to something like embedded php is "Oh how convenient, I can use my main language!" then that would imply the answer is "yes", since, if you do know other languages your natural impulse would be to use pretty much any other language if you have a choice.
Re:PH7 – An Embedded Implementation of PHP (C Library) by a-nom-a-ly on Saturday February 22, 2014 @02:14PM (#7283172)
Well, these arguments of yours aren't the most ridiculous I've ever heard... I'll give you that much.
Re:PH7 – An Embedded Implementation of PHP (C Library) by Kiro on Thursday February 20, 2014 @06:37AM (#7270251)
So having PHP as your main language means you can't learn anything else?
Re:PH7 – An Embedded Implementation of PHP (C Library) by Touche on Wednesday February 19, 2014 @11:21AM (#7264323)
> 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.

Re:PH7 – An Embedded Implementation of PHP (C Library) by aktau on Wednesday February 19, 2014 @11:35AM (#7264418)
You mean so you can distribute a standalone binary that is actually just a bunch of lua? Do you do this so that the users have a harder time modifying the code (just curious)? I'm supposing that this is the case otherwise it would work pretty well with by using the lua or luajit interpreter and some wrapper bash/cmd.exe script to run your lua file(s).
Re:PH7 – An Embedded Implementation of PHP (C Library) by Touche on Wednesday February 19, 2014 @11:43AM (#7264463)
> You mean so you can distribute a standalone binary that is actually just a bunch of lua?

No, I'm saying that you can't. You create a wrapper main.c file that loads and executes the lua. I use a script that tranlates the lua into a C byte array so that I can avoid loading the external lua scripts.

> Do you do this so that the users have a harder time modifying the code (just curious)? I'm supposing that this is the case otherwise it would work pretty well with by using the lua or luajit interpreter and some wrapper bash/cmd.exe script to run your lua file(s).

No, I do it to avoid having to worry about where the .lua scripts are located. Having a single binary is nicety, not required of course.

Re:PH7 – An Embedded Implementation of PHP (C Library) by fsniper on Wednesday February 19, 2014 @12:35PM (#7264806)
I think what you are looking is called a packager. I left The Windows world and scene long time ago but t was very popular in scenes.

With a little search I found out UPX and it seems to be working with many unix binary formats too.. http://upx.sourceforge.net/

Re:PH7 – An Embedded Implementation of PHP (C Library) by coldtea on Wednesday February 19, 2014 @12:20PM (#7264686)
>No, I'm saying that you can't. You create a wrapper main.c file that loads and executes the lua. I use a script that tranlates the lua into a C byte array so that I can avoid loading the external lua scripts.

I think that's what he meant -- that ignoring the small wrapper part --which is boilerplate--, you can deliver a binary that's basically lua.

Re:PH7 – An Embedded Implementation of PHP (C Library) by justincormack on Wednesday February 19, 2014 @12:04PM (#7264587)
LuaJIT can output bytecode as .o files that you can just link. It is not very well documented but its pretty easy once you get the hang of it.
Re:PH7 – An Embedded Implementation of PHP (C Library) by Touche on Wednesday February 19, 2014 @12:29PM (#7264758)
.o files are not executable. You still have to link it to something that executes, and that something isn't Lua.
Re:PH7 – An Embedded Implementation of PHP (C Library) by oscargrouch on Wednesday February 19, 2014 @02:53PM (#7265796)
.o files are executable code.. they are just not a native file executable (elf, coff, mach-o) = headers + .o files
Re:PH7 – An Embedded Implementation of PHP (C Library) by justincormack on Wednesday February 19, 2014 @05:44PM (#7267022)
yeah, you link to lua.a or lua.so and a very small stub to run the code. There is an example here https://github.com/justincormack/ljsyscall/blob/master/examp...
Re:PH7 – An Embedded Implementation of PHP (C Library) by ygra on Wednesday February 19, 2014 @01:30PM (#7265192)
Couldn't you tell the linker to use one of the functions in the .o as entry point?
Re:PH7 – An Embedded Implementation of PHP (C Library) by oscargrouch on Wednesday February 19, 2014 @02:31PM (#7265658)
yes..

1 - create the object files (with luajit?)

2 - create a main() in c.. use "extern" to reference the external symbol in the .o files and call it from main.

The symbols in the object files produced by luajit or whatever need to be exported/ visible.. (are they mangled?)

3 - create a object file for main.c

4 - link the .o created from luajit(or whatever, dart?) and main.o together

If the linker cant find the external symbol it wont link to a binary (so you need to know how, in what names they are exported.. use objdump to lookup for symbols)

Re:PH7 – An Embedded Implementation of PHP (C Library) by Touche on Wednesday February 19, 2014 @01:46PM (#7265317)
Code example?

edit: If so I've been doing it wrong for years.

Re:PH7 – An Embedded Implementation of PHP (C Library) by stephan10h on Wednesday February 19, 2014 @05:37PM (#7266950)
Re:PH7 – An Embedded Implementation of PHP (C Library) by ygra on Thursday February 20, 2014 @12:52AM (#7269131)
ld has a -e argument [−4] (and MSVC's link has /ENTRY [37]). Otherwise, if there is a function with the expected name, calling convention and arguments in the object file I doubt the linker will complain.

[−4] ftp://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_24.html

[37] http://msdn.microsoft.com/library/f9t8842e.aspx

Re:PH7 – An Embedded Implementation of PHP (C Library) by unwind on Wednesday February 19, 2014 @11:23AM (#7264337)
On the other hand, the single-source engine is so large, GitHub won't display it on the web. :/
Re:PH7 – An Embedded Implementation of PHP (C Library) by eksith on Wednesday February 19, 2014 @11:36AM (#7264424)
I was curious why they did that. Just looked at the source and came across this :

  This file is an amalgamation of many separate C source files from PH7 version 2.1.
  By combining all the individual C code files into this single large file, the entire code
  can be compiled as a single translation unit.This allows many compilers to do optimization's
  that would not be possible if the files were compiled separately.Performance improvements
  are commonly seen when PH7 is compiled as a single translation unit.
The target does say for embedded so I guess that's from experience running this on very small resources.
Re:PH7 – An Embedded Implementation of PHP (C Library) by unwind on Wednesday February 19, 2014 @11:41AM (#7264450)
But the glueing together destroys any modularization they had going on, making the code way harder for anyone else to understand and read.

The "typical" solution to that very valid problem is to use the preprocessor, i.e. create a "ph7-master.c" file that simply includes all the real C files.

The comparative overhead of should be negligble, but then the modularization survives.

Re:PH7 – An Embedded Implementation of PHP (C Library) by Touche on Wednesday February 19, 2014 @11:44AM (#7264470)
Or use cat to combine the files prior to compiling.
Re:PH7 – An Embedded Implementation of PHP (C Library) by symisc_devel on Wednesday February 19, 2014 @11:31AM (#7264394)
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.
Re:PH7 – An Embedded Implementation of PHP (C Library) by 72deluxe on Wednesday February 19, 2014 @11:49AM (#7264504)
Also makes it dead easy to download and embed into projects! Hurray for single source files.
Re:PH7 – An Embedded Implementation of PHP (C Library) by kodablah on Wednesday February 19, 2014 @11:24AM (#7264342)
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/.

1 - https://github.com/php/php-src/tree/master/tests 2 - https://github.com/php/php-src/tree/master/Zend/tests

Re:PH7 – An Embedded Implementation of PHP (C Library) by frik on Wednesday February 19, 2014 @01:57PM (#7265385)
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/

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

Re:PH7 – An Embedded Implementation of PHP (C Library) by edsiper2 on Wednesday February 19, 2014 @08:09PM (#7268057)
Unqlite is very good, we use it as our main in-memory key/value store in Duda I/O [http://duda.io].
Re:PH7 – An Embedded Implementation of PHP (C Library) by FigBug on Wednesday February 19, 2014 @11:53AM (#7264520)
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?

Re:PH7 – An Embedded Implementation of PHP (C Library) by symisc_devel on Wednesday February 19, 2014 @12:03PM (#7264582)
Yes, most of the built-in functions (over 470) are foreign C/C++ functions installed exactly using the same interface: ph7_create_function();
Re:PH7 – An Embedded Implementation of PHP (C Library) by stevekemp on Wednesday February 19, 2014 @12:48PM (#7264890)
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.

Re:PH7 – An Embedded Implementation of PHP (C Library) by frik on Wednesday February 19, 2014 @02:13PM (#7265509)
Interesting, please write a blog post if you investigate this. It could be like OpenResty (Lua + Nginx): 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.

Re:PH7 – An Embedded Implementation of PHP (C Library) by captainmuon on Wednesday February 19, 2014 @01:08PM (#7265047)
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.)

Re:PH7 – An Embedded Implementation of PHP (C Library) by webjprgm on Wednesday February 19, 2014 @01:45PM (#7265313)
I usually see arguments like this about language performance, but do people also argue about the difference from having a server process launch, configure itself, and stay open handling requests, like Ruby or Node.js, versus re-running initialization on each request like PHP?

A lot of that initialization code is hooking together objects, reading misc config flags, and setting up request routing. But what about ORM? Ruby's ActiveRecord has to query the database for a schema, right? In PHP that query would be done every request rather than just once when the server restarts.

Could this architecture issue have a larger performance impact than the minor differences in Python / PHP / Javascript / Ruby performance?

(There were also plenty of discussions about event-based programming versus blocking + multi-threading back when Node was becoming popular. That is another example of architecture being more important than execution speed.)

Re:PH7 – An Embedded Implementation of PHP (C Library) by Kiro on Wednesday February 19, 2014 @01:31PM (#7265199)
Is it Python really slower than PHP? If you could notice the slowness it seems like the difference would be pretty large.
Re:PH7 – An Embedded Implementation of PHP (C Library) by camus2 on Wednesday February 19, 2014 @01:49PM (#7265336)
> 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...

Re:PH7 – An Embedded Implementation of PHP (C Library) by RussianCow on Wednesday February 19, 2014 @01:35PM (#7265234)
In my experience the difference in performance of the languages is negligible (assuming you have a solid PHP config). I run sites written in each, and I can't say one has caused me more performance problems than the other; it just depends on what you're doing with them.
Re:PH7 – An Embedded Implementation of PHP (C Library) by TheZenPsycho on Wednesday February 19, 2014 @03:58PM (#7266175)
"I know it's completely backwards nowadays, but funny how what you've learned sticks."
Re:PH7 – An Embedded Implementation of PHP (C Library) by jacob019 on Wednesday February 19, 2014 @12:25PM (#7264729)
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.
Re:PH7 – An Embedded Implementation of PHP (C Library) by sjf on Wednesday February 19, 2014 @12:32PM (#7264783)
If insecurities are part of PHP, no, not unless they deviate from the standard implementation. And there are most likely a bunch of undiscovered stack overflow type insecurities in this new interpreter as well.
Re:PH7 – An Embedded Implementation of PHP (C Library) by davidw on Wednesday February 19, 2014 @12:29PM (#7264761)
If you want an embeddable interpreter, Tcl and Lua are other possibilities.
Re:PH7 – An Embedded Implementation of PHP (C Library) by q3k on Wednesday February 19, 2014 @01:36PM (#7265244)
It might be less secure due to the fact that this is a new, untested and unproved implementation of a pretty quirky language.
Re:PH7 – An Embedded Implementation of PHP (C Library) by andrewmwatson on Wednesday February 19, 2014 @12:33PM (#7264787)
you're right, RoR is WAY more secure...
Re:PH7 – An Embedded Implementation of PHP (C Library) by BlackDeath3 on Wednesday February 19, 2014 @05:55PM (#7267140)
What made you jump to RoR?
Re:PH7 – An Embedded Implementation of PHP (C Library) by zalthor on Wednesday February 19, 2014 @12:16PM (#7264658)
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.
Re:PH7 – An Embedded Implementation of PHP (C Library) by weland on Wednesday February 19, 2014 @01:59PM (#7265401)
Lua is pretty widely used. C is also favoured but it's pretty easy to misuse so there are teams that shy away from it. I've seen Perl, Python and PHP, too, as well as some obscure languages. I distinctly remember seeing Tcl, but I don't remember the context so I might be bullshitting here.

It greatly depends on flash and RAM though. Past a certain point, Python or PHP are just too large.

Re:PH7 – An Embedded Implementation of PHP (C Library) by up-n-atom on Wednesday February 19, 2014 @01:57PM (#7265381)
Re:PH7 – An Embedded Implementation of PHP (C Library) by edsiper2 on Wednesday February 19, 2014 @08:11PM (#7268068)
i would be interested into your evaluation of Duda I/O, let me know your comments.
Re:PH7 – An Embedded Implementation of PHP (C Library) by nifoc on Wednesday February 19, 2014 @12:24PM (#7264725)
The UI (and maybe other parts?) of AVM routers ("FritzBox") is written in Lua.
Re:PH7 – An Embedded Implementation of PHP (C Library) by captainmuon on Wednesday February 19, 2014 @01:00PM (#7264977)
My router from D-Link uses php (at least it has php in the URLs). I've seen some that use custom C programs with a webserver (cgi-bin) too.
Re:PH7 – An Embedded Implementation of PHP (C Library) by z92 on Wednesday February 19, 2014 @12:53PM (#7264928)
Almost everyone use Lua.
Re:PH7 – An Embedded Implementation of PHP (C Library) by ausjke on Wednesday February 19, 2014 @01:58PM (#7265395)
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?
Re:PH7 – An Embedded Implementation of PHP (C Library) by angersock on Wednesday February 19, 2014 @03:39PM (#7266071)
Erm...how would people feel about having this as an available module for Node.js?

No reason. ;)

Re:PH7 – An Embedded Implementation of PHP (C Library) by jbeja on Wednesday February 19, 2014 @06:30PM (#7267422)
...
Re:PH7 – An Embedded Implementation of PHP (C Library) by rlidwka on Wednesday February 19, 2014 @04:41PM (#7266435)
62022 lines of code in a single file... is that a joke? :)
Re:PH7 – An Embedded Implementation of PHP (C Library) by elwell on Wednesday February 19, 2014 @04:03PM (#7266204)
Pretty cool, but why's it all in one .c file?