News for hackers. Stuff that matters.
Re:Hack: a new programming language for HHVM by toast0 on Thursday March 20, 2014 @01:11PM (#7436967)
The HN crowd seems to dislike (or despise perhaps?) PHP, but it's really not that bad. Yes it has a lot of warts, but it has a lot of things that make it nice for web development.

a) try your new code by saving in your editor, and hitting reload in your web browser.

b) it's very approachable. People who only know HTML and CSS can be expected to do a little bit of PHP work to integrate their changes. If you setup the right network mounts, they just need to edit files and reload (see a)

c) it's not super high overhead at runtime. If you're not using a framework, and you don't build up a crazy object hierarchy, it's not too hard to get your page out with about 10 ms of overhead beyond data fetching. For very simple webservices (fetch data, possibly from multiple sources, and do a little formatting for the consumer), I was able to get the overhead down to 2ms. You can certainly do better with other languages, but you can usually get better throughput improvement by working on getting data quickly. Btw, all the frameworks are terrible; many of them add 100 ms to the page just for the privilege of loading the includes; PHP is a framework for web programming thank you very much.

d) cleanup; you don't have to worry about it. If you don't do anything weird (c extensions, with non-preferred malloc), at the end of the request, everything is thrown away.

That said, there are plenty of things PHP isn't good at: I wouldn't run a long running process in PHP; and multithreaded PHP sounds like a bad idea.

Re:Hack: a new programming language for HHVM by ptx on Thursday March 20, 2014 @02:44PM (#7437682)
Yes, PHP is its own web framework, but it's not a very good one. And, as you say, implementing a better one on top of it adds a lot of overhead due to the execution model. With other languages, where you don't throw everything away at the end of the request, you are free to implement a good web framework without suffering additional overhead.

As for a), many (most?) frameworks are able to monitor the source files and reload the application when they change, in order to enable that workflow. For example: http://cherrypy.readthedocs.org/en/latest/refman/process/plu...

Re:Hack: a new programming language for HHVM by bad_user on Friday March 21, 2014 @12:56PM (#7443343)
> a) try your new code by saving in your editor, and hitting reload in your web browser.

The only language for which that works is client-side Javascript. For PHP, you forgot the part in which you have to install and run a web server, then point your browser to localhost. Plus, to get anything useful done, you'll also need some sort of database to go along with it. I remember the first time I did that and it was pretty intimidating.

> c) it's not super high overhead at runtime ... it's not too hard to get your page out with about 10 ms of overhead beyond data fetching

To me much more interesting is the total time it took for the client to receive the response, possibly when multiple concurrent requests are happening. The comparison here should be versus a static page served by Nginx of course.

The best throughput possible that I got for an otherwise complex business logic happened on the JVM. I basically rewrote a web-service built on top of Django/Python, with a redesign with emphasis towards in-memory caching, parallelism and async I/O and the result was a server that was able to process more than 10,000 requests per second with an average of about 5ms per request (actually in production the instances ended up processing about 2000 reqs/sec of real traffic, since c1.medium EC2 instances don't have enough CPU power).

Of course, people that just need to slap something together, don't need this level of throughput. If a request takes 400ms for a dumb web form on a low traffic website, that's of no consequence to most people. The problem happens of course when such a piece of software evolves to something much bigger, like Wordpress. I'm always amazed at the gimmicks that people do just to keep their Wordpress powered blog alive.

Re:Hack: a new programming language for HHVM by Lennie on Friday March 21, 2014 @04:06AM (#7441177)
If you want to know: just checked the one project where I did a long running PHP-process.

It is a job scheduler which takes jobs from a Redis queue and executes it.

It does fork a new process for 1 type of task (image resizing in this case) to make sure it doesn't leak memory.

It also reuses these forked processes so it doesn't need to fork for every task.

It was last started on Jan. 2013 (because of maintenance) and still running fine.

The reason ? I didn't want to introduce an extra language for project for which all the server code was already written in PHP.

So if it fits the task, you can do it.

Re:Hack: a new programming language for HHVM by toast0 on Friday March 21, 2014 @12:37PM (#7443239)
Duly noted, will not be so negative on long running processes. :)
Re:Hack: a new programming language for HHVM by ochekurishvili on Friday March 21, 2014 @02:33AM (#7440966)
I'm running multithreaded background processes in PHP pretty successfully. I did not see (and still do not see) a reason why I should have chosen another "proper" language for it.

P.S. The vast majority of arguments against PHP here leads me to conclusion that most of (not all) debaters don't understand how PHP works well enough.

Re:Hack: a new programming language for HHVM by toast0 on Friday March 21, 2014 @12:36PM (#7443232)
Mulithreaded using the pthreads api or something else? Any chance there's code I could take a look at (I'm curious!)
Re:Hack: a new programming language for HHVM by ochekurishvili on Friday March 21, 2014 @03:08PM (#7444146)
I use curl_multi_* functions.
Re:Hack: a new programming language for HHVM by toast0 on Friday March 21, 2014 @04:59PM (#7444879)
Oh... I don't count curl_multi as multithreaded (because it isn't really threads), but it's very useful, and I definitely use it.
Re:Hack: a new programming language for HHVM by jimbokun on Thursday March 20, 2014 @09:29PM (#7440094)
Has anyone tried to copy these good parts of PHP, except with a not shitty language?

Is there anything about PHP, the language, that lends itself to this style of development, or could you get these same benefits with, say, Ruby or Python?

Re:Hack: a new programming language for HHVM by DeGuerre on Thursday March 20, 2014 @09:55PM (#7440197)
Yes, someone has indeed tried this. It's called "Hack".
Re:Hack: a new programming language for HHVM by justinhj on Thursday March 20, 2014 @07:14PM (#7439552)
There are a lot of people making money writing systems in php because it's the right tool for some jobs. There are companies making money using system that are written in php, because it works. These people don't have as much to say as those working in other languages that may feel threatened or uncomfortable when something they think is bad, seems to used with success.
Re:Hack: a new programming language for HHVM by 1ris on Thursday March 20, 2014 @01:21PM (#7437051)
a) WTH? I hope you do not test your code in production. If you don't that feature (a ide that constantly compiles your code) is a common feature.

b) Theorem: Leting your web designers program is a way worse than letting your programmers do web design.

c) Every simple project can become complex at some point. Facebook certainly is.

Re:Hack: a new programming language for HHVM by sanswork on Thursday March 20, 2014 @01:26PM (#7437098)
a) You don't have a development server/VM?

b) Not everyone has programmers. That was his point

Re:Hack: a new programming language for HHVM by 1ris on Thursday March 20, 2014 @01:58PM (#7437362)
Oh, for b) i know a bonmot. Sorry for the image. http://fettemama.org:6502/ed2499a7aa73df6dcefe95fbb649ece3
Re:Hack: a new programming language for HHVM by sanswork on Thursday March 20, 2014 @02:09PM (#7437439)
Not everyone that needs/wants to make a website wants to start a software development company. Often then just want to accomplish a few small things. To match up the rest of your examples:

I was to defend myself in small claims court

I want to learn some first aid

I want to build a shed behind my house