News for hackers. Stuff that matters.
Re:PHP Sucks But I Like It by api on Tuesday April 10, 2012 @06:40PM (#3824857)
The secret to PHP's success is simple. I've never seen anyone point it out.

It just works.

If you have a web server configured to run PHP, then it's ridiculously simple to get a page to execute. Just put a .php file on the site and it runs. Done.

You don't have to jigger a bunch of components, dink around with a bunch of Tomcat or Ruby on Rails or proxy or other annoying settings. Most other web execution environments have a bunch of Rube Goldberg machine components you have to plug together to get them to work. It also performs very well and supports a lot of things.

Re:PHP Sucks But I Like It by Lazare on Tuesday April 10, 2012 @07:13PM (#3824980)
True. A lot of webhosts are configured such that you can drop some PHP files into a directory via ftp, and it'll "just work". Which is nice. But...

...that's not really inherent in PHP. You can configure Python to be just as easy, and some webhosts do this. Node is pretty much always this easy. Django and Rails can also be this easy (if you've ever used Webfaction, you'll know what I'm talking about).

And, on the flip side, if you want to install configure PHP yourself, it's actually not that easy. It's trivial to get a PHP page to execute given a web server configured to make it trivial (but, again, that's true for almost any language), but configuring the web server isn't trivial.

Re:PHP Sucks But I Like It by CJefferson on Tuesday April 10, 2012 @08:13PM (#3825200)
PHP's hello world, for transmitting back to the user, is:

<?php Print "Hello, World"; ?>

I can wrap that in a little HTML, to get valid return to the user.

I don't know what Node.js's hello world looks like. From google it looks like the following. This is a heck of a lot more things to understand.

// Load the http module to create an http server. var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests. var server = http.createServer(function (request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.end("Hello World\n"); });

// Listen on port 8000, IP defaults to 127.0.0.1 server.listen(8000);

// Put a friendly message on the terminal console.log("Server running at http://127.0.0.1:8000/);

Re:PHP Sucks But I Like It by Lazare on Tuesday April 10, 2012 @08:47PM (#3825337)
Actually, you'd probably want Express.

  var app = express.createServer();
  app.get('/', function(req, res){
      res.send('Hello World');
  });
  app.listen(3000);
That is, admittedly, longer than PHP but it's arguably easier to understand what's going on, much easier to modify and extend, and just as easy to copy and paste off the web.

For Sinatra:

  require 'sinatra'
  get '/' do
    "Hello World!"
  end
Again, does PHP have any real advantage here? Python solutions will be similar. And in all those cases we can turn this into a full app with only a few more lines.

Consider this example of a completely function blog: https://github.com/mitsuhiko/flask/tree/master/examples/flas...

There's 76 sloc of code in the blog app, plus tests, templates, database access, and more. And it's clean, clear, and simple. What does the PHP equivalent look like?

Of course, PHP is still shorter for hello world...mostly because it's running as a CGI app. This is a terrible, archaic idea for all the reasons that get discussed when people talk about Why PHP Is Terrible, but nothing is stopping you from configuring other languages that way. So here's a real apples-to-apples comparison:

Python:

  print "Hello world!"
Too long? Try Ruby:

  puts "Hello world!"
19 characters including white space? Beat that! :)
Re:PHP Sucks But I Like It by greggman on Tuesday April 10, 2012 @11:37PM (#3825802)
No they aren't easier to understand, not by a long shot.

Imagine you're some mom who's made a static website for some group you're a member of. You made 20-30 static pages with Frontpage or something like it.

It's a much MUCH smaller step to rename a file .php and add

    <?date('Y-m-d')?>
Than it is to wrap your head around what that node JS or python is doing.

It's exactly that integration that makes PHP win. If someone would make a similar integration for a better language (and made it fit the other niches that PHP fits that nothing else does) they'd stand a great chance of changing the world.

The problem is, no one gets it. Just like you you're fundamentally missing what people like about PHP. It's not the language that they like. It's that it's HTML+server scripting. No setup needed, no external files needed, no libraries to learn, no security issues at least at the start. It just works, in small increments above the level of static HTML.

Re:PHP Sucks But I Like It by maratd on Wednesday April 11, 2012 @12:05AM (#3825872)
So you walk into a culinary studio and they're having this intense class on how to properly prepare escargot.

And you stare at them ... and tell them they should just make a peanut-butter sandwich. They stare at you blankly. Then they tell you to go #$%$#^ yourself.

Is the peanut-butter sandwich easier to make? Yes. Does it taste better? Yes. Can you use it to feed the masses? Yes.

But sir, you forget. It isn't gourmet!

Re:PHP Sucks But I Like It by ch0wn on Wednesday April 11, 2012 @03:09AM (#3826343)
Great analogy. I never got the arguments telling you it's so simple to change little things. When is this ever useful except for when you just get started? It only takes a couple of hours until you leave the zone where small modifications are handy and you need to structure your code, mostly using some MV*-approach.
Re:PHP Sucks But I Like It by JohnnyFlash on Wednesday April 11, 2012 @03:49AM (#3826430)
Adding: <?date('Y-m-d')?>

Would whiff...

Either short tags would be disabled and cause an error. Or nothing would happen.

<?php echo date('Y-m-d')?> -- Would be most preferable.

<?=date('Y-m-d')?> -- Won't work on half of webservers.

PHP is simple but most PHP servers are terrible. Part of my job is to ensure the smooth installation of proprietary software on around 1000 servers a year. This is the painful part of PHP development. If the client is paying less than $5/mo for hosting then I often run into problems with misconfigured servers, common features being disabled.. hell.. shit not working! Why isn't it working? I don't know. There are no errors. There is nothing logged... yet for some reason the session only lasts 7 seconds before disappearing.. yay!

I love PHP because it is simple and just works... I really dislike 80% of shared hosting providers who cause all sorts of problems with what should be a simple cross platform application.

Re:PHP Sucks But I Like It by mgkimsal on Wednesday April 11, 2012 @07:33AM (#3826974)
Yeah, OK, I'll bite...

"<?=date('Y-m-d')?> -- Won't work on half of webservers."

You're referring to shorttags, and how evil they are. Firstly, PHP 5.4 enshrines this echo shortcut usage, and they'll always be on from now on. <?=$something;?> will always work from 5.4 on.

Secondly, "half"? Where the hell are these mythical 50% of web servers that actively disable short tags? I've been working with PHP since 1996, have worked on hundreds of projects on dozens of hosts - shared and dedicated - over those years, and have come across this once, on a server managed by someone who compiled everything by hand (not just PHP, but everything) and felt turning short tags off was "optimal" because he'd read it somewhere. He wasn't a PHP dev, just had read 'short tags are bad'.

I don't doubt that some admins and hosts do turn off short tags. It is no where close to 50% of servers out in the wild though. 5% perhaps? Even that, in my view, would be a huge stretch.

Re:PHP Sucks But I Like It by alanh on Wednesday April 11, 2012 @11:51AM (#3828084)
Surely you realize that PHP is alone in having vast swaths of its common functionalitity disabled by hosts because of massive security problems arising in actual use?

This means PHP being crippled on many servers is PHP’s own fault.

Re:PHP Sucks But I Like It by wanderful on Wednesday April 11, 2012 @01:16PM (#3828513)
Not necessarily. Popularity makes something more likely to be exploited. Compare PCs to Macs re: viruses. Also, many security issues were due to conventions in early versions of the language, e.g. register globals.
Re:PHP Sucks But I Like It by grey-area on Saturday April 14, 2012 @10:24AM (#3840904)
This is the main strength, and also one of the most obvious flaws, of PHP. What makes it incredibly easy to get started (if you start from static HTML) also makes it easy to trip yourself up later on.

Mixing logic and your text/data will work well for inserting a simple date, but when you start adding more complicated logic it is easy to create a mess which is difficult to read and modify even for you a few months later. That's the reason other frameworks/languages try to give you a more structured (and complex) starting point.

Re:PHP Sucks But I Like It by antihero on Wednesday April 11, 2012 @07:18AM (#3826915)
By "win", of course, you mean develop a giant ecosystem of abysmal code that decent developers flee from at any given opportunity, right?
Re:PHP Sucks But I Like It by CJefferson on Tuesday April 10, 2012 @09:21PM (#3825447)
Your examples are interesting, I may look at Sinatra and flask.

One other big advantage of PHP, which I find as time goes by, is (boringly) its broad stability. I first learnt PHP over 10 years ago, and what I learnt then still works now. Web apps are a very small part of what I do, I knock together the odd small one every couple of years or so.

I did do one app in Rails, but when I next came back to look at Rails about 18 months later, it seemed enough things had changed my app broke in various ways. I find I increasingly appreciate a large community, a book or two, and some stability.

Obviously if your day-to-day life is web design that doesn't apply. My day-to-day life in high performance algorithms, and I was using new C++11 features as they got implemented in compilers, and have played with many languages in that area.

Re:PHP Sucks But I Like It by gauravk92 on Wednesday April 11, 2012 @12:22AM (#3825906)
I'd love an experts opinion on c++11 in the realm of high performance algorithms. Considering most of the updates were instruction additions and fixes, is it really increasing speed and even worth it to use the bleeding edge for maybe some small gain where a 10 year old language is simply much more reliable?

Also, I didn't mention the updates in parallelism that were added (because they should have come earlier)...but do you think c++ is comparable to a modern concurrent language atm? Worth it over erlang?

Re:PHP Sucks But I Like It by CJefferson on Wednesday April 11, 2012 @06:32AM (#3826808)
I wouldn't sat that C++11 is going to lead to faster code than C++03. However, if like many C++03 experts you were already writing a lot of template code, then 'decltype' and variadic templates in particular make a lot of templated code much easier and cleaner to write. lambda functions neaten up various things.

Other people may have different opinions, but I don't think C++11 will convert anyone, but people who already have a big time, or code, investment in C++ will find much of their lives much easier. Another indirect advantage is that by moving to C++11, it finally allows people to make a clean break from older, less standard C++ compilers. Wether will we end up with a new state, where people end up supporting partial C++11 compilers, we will have to wait and see.

The parallelism is really just standardising existing behaviour in many cases. People who want to write things like lock-free algorithms are very excited by the atomics stuff, but such stuff is beyond me.

I am disappointed that some more practically useful threading algorithms, like thread pools and such like did not end up in the standard. However they now seem to be arriving as 3rd party libraries.

I think what is going on is that before a threadpool library was '2 steps removed' from standard C++ (as first you had to write, or use someone else's, threading/atomics library). Now they are only '1 step removed', they are more useful.

Re:PHP Sucks But I Like It by pjmlp on Wednesday April 11, 2012 @06:10AM (#3826759)
If you want ultimate performance yes.

In modern architectures there are lots of places where you can get way faster, just by organizing your data in more cache friendly ways, or the way the data is layered across registers and memory regions.

You need a language like C++ for these type of optimizations.

Re:PHP Sucks But I Like It by justauser on Tuesday April 10, 2012 @11:34PM (#3825795)
Maybe a better comparison is from some of the microframeworks for PHP. As you can see, Sinatra influenced a lot of frameworks in many languages.

From Slim: (http://www.slimframework.com/)

require 'Slim/Slim.php';

$app = new Slim();

$app->get('/hello/:name', function ($name) { echo "Hello, $name!"; });

$app->run();

From Silex: (http://silex.sensiolabs.org/)

require_once __DIR__.'/silex.phar';

$app = new Silex\Application();

$app->get('/hello/{name}', function($name) use($app) { return 'Hello '.$app->escape($name); });

$app->run();

Re:PHP Sucks But I Like It by markelliot on Tuesday April 10, 2012 @11:30PM (#3825782)
The trivial example of PHP is equivalent to making a file with only the text:

  Hello World!
...and saving it as a .php file. I think you'll have a hard time finding something more concise. :)

In reality, one of the things that makes PHP an easy language to pick up is that you don't have to have all of the overhead of learning how it works. Novices sprinkle bits of PHP surrounded by HTML-looking tags and all of the sudden they're up and running.

I started with PHP myself, and found it to be an interesting and frustrating language (needle or haystack argument first?). It's often saved by an easily searchable manual and a huge user base.

PHP is a shoot-yourself-in-the-foot language. It'll happily let you do dangerous, awful, bad, bad things. This wouldn't be such an issue if there was a higher barrier to entry, the real problem is it's easy to pick up (is that really a "problem"?), but that's a feature not a bug.

Re:PHP Sucks But I Like It by Isofarro on Wednesday April 11, 2012 @08:18AM (#3827136)
This highlights PHP's core strength. The incremental effort to add dynamic content to an existing static website is very low. Even for an existing page. Right from the start, every existing page is already ready for PHP to be added.

At worst, all you may need is to ensure .html prefixed resources as processed as HTML files: http://docs.grabaperch.com/getting-started/file-extensions

Re:PHP Sucks But I Like It by nikcub on Wednesday April 11, 2012 @07:26AM (#3826941)
It would be interesting to create a javascript server-side environment where code is in blocks and is executed through server modules.

The benefit of being able to output HTML by default, drag+drop files over FTP or SCP to get it working, and a lanaguge that a lot of developers already know through client scripting.

I wonder if ASP still has support for Javascript as a server lanagage.

An example would be something like:

    <%
    	require('mysql');
    	require('session');
    	require('cookie');
    	require('datetime');

    	blog_data = mysql.fetch('select * from blog_meta');
    	posts = mysql.fetch('select title, content, author, pubdate, permalink from posts where published=1 order by pubdate desc');
    	user = session.get_current(cookie.sess_id);
    %>
    <!DOCTYPE html>
    <html>
    <head>
    	<meta charset="utf-8" />
    	<title><%= blog_data.title %></title>
    </head>
    <body id="home">
    <div class="container">
    	<% for post in posts: %>
    		<div id="post-<% post.id %>">
    			<a href="<% post.permalink %>">
    				<h1><%=post.title %></h1>
    			</a>
    			<div class="postmeta">
    				<%=post.author %> - <%= post.pubdate.format('%m %d %Y') %>
    			</div>
    			<div class="content">
    				<%=post.content %>
    			</div>
    		</div>
    	<% endfor %>
    </div>
    </body>
    </html>
as simple as PHP, but Javascript - and simple webapp modules like session, mysql, etc. etc.
Re:PHP Sucks But I Like It by _3u10 on Tuesday April 10, 2012 @08:20PM (#3825227)
Yes, PHP is awesome for building hello world applications. No one is disputing that.

However, for building applications that might get deployed somewhere, or talk to a database in a secure fashion, it's a nightmare.

For ruby, python and perl, it's just as easy to make a hello world like that, all you have to do is execute it as a CGI. Node.js is a FRAMEWORK, not a language, you can equally make it super simple to execute javascript the same way by again executing it at as CGI, it's actually even shorter because you don't need <? ?> tags.

The reason the Perl,Python and Ruby communities don't make apps like that is because it's a bad idea. In ruby,perl,python,javascript if you really want to you can. PHP makes it incredibly hard to not be stupid in the way your app is setup. PHP saves you a few minutes of following a rails cast in exchange for a lifetime of hell.

The crux of why most programmers disdain PHP is because of the poor choices for maintainability and ease of building larger applications, also because the PHP community has no idea what they're talking about for the most part.

Most PHP programmers couldn't even tell the difference between a language, a framework, a template system, probably because PHP doesn't have any separation of concerns. The language, framework, standard library, templating system are all mashed into one godawful mess.

But yes, it's really easy to build hello world applications. Alternatively, if you want to build a hello world application you could just write:

  Hello World
in a text file and be done with it instead of exposing yourself to all the security vulnerabilities inherent in PHP. (Yes, even hello world is insecure in PHP)
Re:PHP Sucks But I Like It by maratd on Tuesday April 10, 2012 @10:42PM (#3825666)
> However, for building applications that might get deployed somewhere, or talk to a database in a secure fashion, it's a nightmare.

In what decade? Ever heard of PDO? Prepared statements? PHP is actually more secure when it comes to database connections than all of the wonderful alternatives you mentioned.

Re:PHP Sucks But I Like It by fuzzix on Wednesday April 11, 2012 @04:42AM (#3826548)
"Prepared statements? PHP is actually more secure..."

The most commonly used module for mysql access, mysql (not mysqli for some reason), does not support bound parameter prepared statements instead opting for some very funky string escaping business.

Prepared statements are generally the only supported SQL mechanism in other languages/platforms I have used (C, Perl, Ruby, Java, COBOL...)

Re:PHP Sucks But I Like It by briandear on Tuesday April 10, 2012 @11:31PM (#3825783)
More secure? Then I suppose I'll get all of the insurance and banking portals to rewrite everything in PHP -- since is so secure and easy to use.
Re:PHP Sucks But I Like It by maratd on Tuesday April 10, 2012 @11:48PM (#3825827)
> Then I suppose I'll get all of the insurance and banking portals to rewrite everything in PHP

From COBOL? Probably a good idea.

Re:PHP Sucks But I Like It by kamaal on Tuesday April 10, 2012 @11:26PM (#3825774)
>>However, for building applications that might get deployed somewhere, or talk to a database in a secure fashion, it's a nightmare.

Facebook, Wikipedia are begging to disagree.

Re:PHP Sucks But I Like It by Legion on Tuesday April 10, 2012 @11:38PM (#3825806)
No, they aren't.

Quote Adam D'Angelo, former CTO of Facebook: "PHP was out of the question [for building Quora]. Facebook is stuck on that for legacy reasons, not because it's the best choice right now". (source: http://www.quora.com/Quora-Infrastructure/Why-did-Quora-choo...)

[deleted]
Re:PHP Sucks But I Like It by sgerrand on Wednesday April 11, 2012 @12:01AM (#3825869)
Actually Facebook agrees with me so much that they rewrote PHP as a C++ macro called hiphop, and no longer use PHP.

A specious comment - hiphop transforms PHP to optimised C++ and then compiles it.

https://github.com/facebook/hiphop-php

Re:PHP Sucks But I Like It by scriptproof on Wednesday April 11, 2012 @12:32PM (#3828289)
Compilation = converting a language into another. Hiphop is a (two-stages) PHP compiler.
Re:PHP Sucks But I Like It by josegonzalez on Tuesday April 10, 2012 @08:54PM (#3825356)
Please explain to me how "hello world" is insecure in PHP. I am genuinely interested in your reasoning.
Re:PHP Sucks But I Like It by _3u10 on Tuesday April 10, 2012 @09:17PM (#3825431)
PHP has had numerous security issues related to the parsing of things like HTTP headers, etc. This means that when you write your app in PHP, and do something simple you get security issues just for going along for the ride.

Things like this: https://bugzilla.redhat.com/show_bug.cgi?id=786686

Put an empty PHP file on your server and you've got a vulnerability. If they can't figure out how to parse a URL correctly what else is lurking? Ironically, the issue is a fix for a DOS attack, so they traded a DOS attack for remote code exec, and then backported it.

This is the equivalent of

  int main() { return 0; } 
having security issues.

By the way, this issue is from two months ago, we're not even talking about the really bad ancient bugs.

Re:PHP Sucks But I Like It by josegonzalez on Tuesday April 10, 2012 @09:23PM (#3825451)
Since I cannot reply to your response, I would like to inquire as to some resources where I can read more about the specific security bugs in PHP you are mentioning.

I am well aware that PHP has had security issues in the past, but I am also aware of the fact that it gets a bad name because people read blog posts and then decide the sky is falling.

Re:PHP Sucks But I Like It by Jach on Wednesday April 11, 2012 @12:59AM (#3826008)
Let's look at something trivially more complex than a Hello World: a form handler. The form is just HTML, asking for a name:

    <html>
    <body>
    <form action="handlerhere" method="post">
    <label>Name: <input type="text" name="name" /></label>
    <input type="submit" name="submit" value="Submit" />
    <input type="hidden" name="submitted" value="TRUE" />
    </form>
    </body>
    </html>
The handler is a separate file. This whole example is from back around my first year of programming, when (among other silly things) I thought indentation was stupid. (Which was one reason I didn't like Python to begin with even though I love it now.) The PHP handler:

    <html>
    <body>
    <?php
    if (isset($_POST['submitted'])) {
    $name = htmlentities(stripslashes($_POST['name']));
    echo "<p>The submitted name was \"$name\"</p>";
    }
    ?>
    </body>
    </html>
And the Python version (notice the silly one space indent (I use two now!) and the silly semicolons):

    #!/usr/bin/python
    import cgi;
    def main():
     form = cgi.FieldStorage(); # instantiate only once!
     name = form.getfirst('name', 'empty');
     
     # Avoid script injection escaping the user input
     name = cgi.escape(name);
     
     print "Content-Type: text/html\n";
     print """\
     <html>
     <body>
     <p>The submitted name was "%s"</p>
     </body>
     </html>""" % name

    if __name__ == "__main__":
     main();
Oh, and with the Python version I had to add this file to the directory it was in which I didn't totally understand at the time:

    Options +ExecCGI
    AddHandler cgi-script .py
    Options +Indexes
Admittedly not that hard. I had an .htaccess file already for fun 404 handlers. I vaguely remember being confused for a while because the .py script didn't have the right permissions on it so the server's apache just refused to execute.

The complexity isn't that much different, it's just that Python provided no compelling reason for me to switch to it. (And, frankly, even with Flask still doesn't for simple single-file web-page scripts. Applications, on the other hand...)

Re:PHP Sucks But I Like It by jacobr on Wednesday April 11, 2012 @02:06AM (#3826172)
What should I do with that PHP script alone? The same example in Node, with no web server, just like yours:

    console.log('Hello World')
Re:PHP Sucks But I Like It by maratd on Tuesday April 10, 2012 @07:35PM (#3825069)
> And, on the flip side, if you want to install configure PHP yourself, it's actually not that easy.

http://www.lifelinux.com/how-to-install-nginx-and-php-fpm-on...

Looks pretty easy to me.

Then again, I compile my own version of Apache with FastCGI and PHP-FPM all the time.

Re:PHP Sucks But I Like It by Lazare on Tuesday April 10, 2012 @07:58PM (#3825148)
True, that's pretty easy. But it's also just as easy as getting most other language or frameworks up and running. And since the argument I was replying to was that PHP was good because those other languages are too hard to configure then, implicitly, PHP is too hard to configure - at least for the guy I was replying to.

And if you're relying on your webhost having your language-of-choice already configured for you, well, you can find webhosts with most of the obvious choices already configured. So what does that leave?

I would suggest that PHP does not, today, have any advantage over other competing languages and frameworks in the "it just works" sweepstakes.

Re:PHP Sucks But I Like It by tambourine_man on Tuesday April 10, 2012 @07:42PM (#3825094)
Was going to say the same, yum makes it very easy.

What we need is a Douglas Crockford for PHP.

A “PHP: the good parts” and a good PHPlint would do wonders to the language and community.

Re:PHP Sucks But I Like It by sgerrand on Tuesday April 10, 2012 @11:59PM (#3825861)
As previously discussed on HN, Robert Eisele's fork of PHP (at v5.3.6) which attempts to fix many of the issues.

http://www.xarg.org/2011/06/php-hacking/

Re:PHP Sucks But I Like It by brendano on Tuesday April 10, 2012 @10:30PM (#3825640)
...that's not really inherent in PHP. You can configure Python to be just as easy, and some webhosts do this...

It's very rare to find webhosts that configure Python, Ruby, Node or the rest to be as easy as "upload a file, click reload."

One reason is the wonderful statelessness of mod_php's execution model: it forks a new process for every request, and destroys it at the end. It's inherently a much more stable environment than the competitors -- you can't save anything inside the interpreter for future requests. This makes server administration easy, and probably shared hosting easier to manage.

Re:PHP Sucks But I Like It by Lazare on Tuesday April 10, 2012 @11:13PM (#3825747)
The original comment said "If you have a web server configured [for PHP] then it's ridiculously simple to get a page to execute."

My point was that this is true for any language.

You seem to be suggesting that the odds of picking a web server at random and having it be so configured for a given language is pretty low, which seems like quite a different issue, and (in my view) a pointless one. Nobody picks a webhost at random and just hopes that they have support, so the question is can you find support if you want it. :)

In any case, it's also incorrect in the case of Python and arguably Ruby. The first three mass-market shared webhosts I can think of are Dreamhost, Webfaction, and Hostgator. Without any configuration at all, Dreamhost supports both Python and Ruby scripts as CGI programs, Hostgator supports Python scripts as CGI programs, and I believe Webfaction does as well.

(Node is a lot newer and, admittedly, doesn't seem to have any support among mass-market shared webhosts.)

Re:PHP Sucks But I Like It by brendano on Wednesday April 11, 2012 @12:28AM (#3825924)
PHP is much better than CGI, because it doesn't have to load an interpreter and all libraries per request -- they were loaded at server startup time. This is why all serious web frameworks don't use CGI. But PHP avoids the administrative/stability problems of persistent servers -- Python, Java, Ruby -- by disallowing state across requests.

I think, because PHP servers are so stable, that's part of why they're so common on shared web hosts. For example, running a WSGI server is much more complicated. If a WSGI app goes bonkers you have to restart the relevant server. In mod_php, just kill the process.

What would be interesting is a forking-style server for Python or another reasonable language.

Re:PHP Sucks But I Like It by Lazare on Wednesday April 11, 2012 @01:19AM (#3826057)
Um. We're getting a little bogged down here, but...

1) PHP is commonly implemented via CGI by many webhosts, even today. Not only is it generally considered more secure, but it lets you easily run multiple versions behind the same Apache instance. The performance hit isn't bad, either. So I'm not sure what "PHP is ... better than CGI" even means.

2) PHP is not particularly stable and it is not uncommon for a PHP process to hang until killed, often soaking up 100% CPU time. The stateless nature does make it easier to just kill it whenever it goes crazy, but it doesn't really have anything to do with how often it goes crazy.

3) You can configure servers in all sorts of ways, but there's nothing inherently harder about WSGI. You absolutely can just "kill the process".

4) I honestly have no idea what you mean by "a forking-style server for Python". Is there something you dislike about all the current ones? :)

Re:PHP Sucks But I Like It by Lazare on Wednesday April 11, 2012 @08:54AM (#3827247)
People seem really hung up on the idea that Python and WSGI are not supported by cheap shared webhosts. If you ever think "gee, I wish I had some decent shared WSGI hosting for less than $10/month" the answer is Webfaction. :)

http://news.ycombinator.com/item?id=3826416

(@lmm: Sorry, I can't reply directly to your post.)

Re:PHP Sucks But I Like It by lmm on Wednesday April 11, 2012 @08:31AM (#3827179)
> 3) You can configure servers in all sorts of ways, but there's nothing inherently harder about WSGI.

I'm willing to believe this - but if it's true, where are the cheap shared webhosts with WSGI enabled? Or do you think there's some other reason PHP is so much more widely available?

Re:PHP Sucks But I Like It by slurgfest on Wednesday April 11, 2012 @12:56AM (#3825999)
It isn't true that "if a WSGI app goes bonkers you have to restart the relevant server." This is between you and your specific app server, it isn't a matter of WSGI.
Re:PHP Sucks But I Like It by brendano on Wednesday April 11, 2012 @09:42AM (#3827452)
PHP has no app servers to go bonkers.
Re:PHP Sucks But I Like It by sciurus on Wednesday April 11, 2012 @12:34AM (#3825942)
Dreamhost supports ruby via phusion passenger now.

http://wiki.dreamhost.com/Passenger

Re:PHP Sucks But I Like It by jrockway on Tuesday April 10, 2012 @06:45PM (#3824881)
Isn't not programming at all even easier? You don't have to get money, find a computer to buy, buy a computer, install an OS, buy an Internet connection, install a web browser, learn to browse the web, learn about how hosting works, find a host, get money to buy a hosting account, learn about apache, install apache, learn about php, install php, learn about text editors, install a text editor, learn php, write PHP, learn about scp, install scp, scp file to server. By the time you've become that proficient with all that stuff, apt-get install libcatalyst-perl on your desktop sounds about as easy as finding a host that supports PHP.

It's not like PHP solves any of the real problems, like how to manage upstream changes, how to automate releases, how to rollback database schemas after a bad release, and so on. The reason why nobody ever talks about those things is because everyone handles them with downtime and swearing. That's not software engineering. That's fail.

Re:PHP Sucks But I Like It by furyofantares on Tuesday April 10, 2012 @06:55PM (#3824910)
Not programming at all is easier, yes. Not programming is also much more popular than programming in PHP.

Edit: To be a bit less snarky here, you are arguing that the sunk costs of learning to use a computer justify more effort spent in getting a web site running just because the effort already sunk dwarfs the additional effort required. But in fact not only is that cost sunk but once I've learned to use a computer my time and energy is suddenly more valuable.

Re:PHP Sucks But I Like It by sbandyopadhyay on Tuesday April 10, 2012 @06:58PM (#3824924)
False dichotomy. You can do some things quickly in PHP (vs other languages), and some things in life and in programming need to be done quickly.

There's a place for doing things fast, and a place for doing things right. You're wrong to assume everything requires the latter.

Re:PHP Sucks But I Like It by justinjlynn on Tuesday April 10, 2012 @07:02PM (#3824939)
If you don't have time to do things right, how are you ever going to find time to do them over and over again?
Re:PHP Sucks But I Like It by sbandyopadhyay on Tuesday April 10, 2012 @07:10PM (#3824967)
Sometimes, doing things fast opens up opportunities to do things right.
Re:PHP Sucks But I Like It by justinjlynn on Tuesday April 10, 2012 @10:47PM (#3825678)
This is true. However, if you do things fast and wrong, you've got an even bigger problem in figuring it out how to do things right because now you have to do both at the same time, and usually with the same number of people.
Re:PHP Sucks But I Like It by justinjlynn on Tuesday April 10, 2012 @10:48PM (#3825683)
You know, not only that, but this implies that wrong is always fast. That is wrong. Often, wrong goes slower as time goes on. I'd rather have slow, steady progress than explosive growth and eventual failure.
Re:PHP Sucks But I Like It by epochwolf on Wednesday April 11, 2012 @11:51AM (#3828088)
I've got some legacy apps I work on that prove that wrong. :)
Re:PHP Sucks But I Like It by gbog on Tuesday April 10, 2012 @09:01PM (#3825377)
False dichotomy too. When I was kid my parents always required me too do things "vite et bien" (fast and well) and it its only much later, with more experience and also some understanding of what is said by Zhuangzi the Taoist, that I understood that both are compatible, and even require each other. Example: if you tidy up your room, doing it slowly means focusing on ordering your Lego by size and color, while doing it fast means moving everything to their place in less than 5 mn.
Re:PHP Sucks But I Like It by fffggg on Wednesday April 11, 2012 @01:25AM (#3826069)
This is truer than you know, but for the wrong reasons.

I worked tech support for a shell provider in the 90s and I helped a LOT of users work through the mechanics of setting up a cgi-bin. One of the most difficult concepts for users without a technical background was file permissions -- specifically the execute bit.

I believe PHP's ease of use primarily stems from what most would consider a security vulnerability: mod_php instructs apache to execute code from php files without the execute bit set. This is inherently the same sort of issue behind email worms on Windows -- exec handlers which pass code to an interpreter without honoring the lack of execute permissions.

It's a terrible idea, and also widely popular. I have personally seen users switch from Perl to PHP purely because they could not figure out how to set the execute bit in their Windows FTP program.

The rest is inertia, as far as I'm concerned.

Re:PHP Sucks But I Like It by MartinCron on Tuesday April 10, 2012 @07:14PM (#3824989)
I've seen people point it out before and I think it makes perfect sense for explaining its popularity.

I also think it's a micro-optimization for the wrong thing. It's like buying a car based solely on how close the dealership is to your house. You only have to do the initial setup once (by definition) but you have to live with the consequences of your environment of choice every single day for the rest of the project.

I'll go to a crappy coffee shop if it's the only one around, I'm willing to go very far out of my way to get to the car dealership that has the right thing for me.

Re:PHP Sucks But I Like It by sbandyopadhyay on Tuesday April 10, 2012 @07:17PM (#3825002)
People trade up cars all the time -- when you can afford to, that is.
Re:PHP Sucks But I Like It by MartinCron on Tuesday April 10, 2012 @07:20PM (#3825013)
Using PHP just because it's easy install isn't like buying a cheap car because it's cheap, it's like buying a cheap car because it's just a little bit closer to walk to than another cheap car.
Re:PHP Sucks But I Like It by sbandyopadhyay on Tuesday April 10, 2012 @07:26PM (#3825039)
To the extent that learning languages takes time (it does) and to the extent that setting up an environment takes times (it does) and to the extent that time is money (it is), I'd say using PHP in lieu of a premium language is exactly like saving money on a car when you don't have a lot of [time/money].

But in the end, what's most important is that the car/language gets you from Point A to Point B.

Re:PHP Sucks But I Like It by MartinCron on Tuesday April 10, 2012 @07:36PM (#3825074)
It's only saving money when you don't count the ongoing opportunity cost of using inferior tools and technologies, but that's a false economy. It's a short-term savings in exchange for lots and lots of serious pain going forward.
Re:PHP Sucks But I Like It by alanh on Tuesday April 10, 2012 @07:13PM (#3824981)
> I’ve never seen anyone point it out.

Really?

The easy of deploying a single-purpose script / hello world is always trotted out as the reason PHP ever became popular.

Yes, even in yesterday’s big item “PHP: A Fractal of Bad Design.”

Re:PHP Sucks But I Like It by fleitz on Tuesday April 10, 2012 @08:09PM (#3825181)
PHP is just an example of worse is better (whose key is simplicity of implementation), because PHP is easy to get started with things get built in it. Then you have a lifetime of maintenance hacking around all the bad decisions at the start because of it.

Comparing the rails app config system to PHP.INI, ini_set, .htaccess and the million other ways to configure PHP and considering the app config system to be a rube goldberg machine is really unjustified, the very configuration of PHP itself pretty much non-deterministic.

http://www.jwz.org/doc/worse-is-better.html

Re:PHP Sucks But I Like It by josegonzalez on Tuesday April 10, 2012 @08:56PM (#3825365)
Don't use all those ways of configuring PHP. php.ini works just fine, and if you truly need a different configuration for a specific application, a bootstrap file will serve to override the php.ini where necessary. Done.
Re:PHP Sucks But I Like It by sgerrand on Tuesday April 10, 2012 @11:54PM (#3825840)
A large number of people have previously pointed this out. You're selling the virtues of mod_php, rather than PHP itself.

As other have pointed out in this thread, you can easily configure a web server to behave like that for files in other languages like Perl or Python.

Re:PHP Sucks But I Like It by RandallBrown on Wednesday April 11, 2012 @03:15AM (#3826354)
but the difference is that you don't have to configure a web server to act like that for PHP, because (almost) all of them come that way.
Re:PHP Sucks But I Like It by emperorcezar on Tuesday April 10, 2012 @09:08PM (#3825402)
Yes, it just works. That's also where there are thousands of poorly written sites out there that chug down sql injections like they were going out of style.

PHP is a reasonable templating language. That's what it should be used for.

If you use a framework, you're golden, but at that point you could be using any language.

Re:PHP Sucks But I Like It by sbarre on Tuesday April 10, 2012 @09:50PM (#3825530)
If [language of your choice] was as popular as PHP you can bet that there would be thousands of poorly written sites in that language out there too.
Re:PHP Sucks But I Like It by TylerE on Wednesday April 11, 2012 @08:59AM (#3827272)
I sincerely doubt that. PHP has fundamental issues.

It's like the people 10 years ago saying "if [other OS] was as popular as Windows XP, it'd be overrun with malware too". No. The issue wasn't Windows marketshare, it was the completely crap security.

Re:PHP Sucks But I Like It by chunkybacon on Thursday April 12, 2012 @09:36AM (#3832219)
The issue was both Windows marketshare and crap security. If it wasn't easy to write malware for Windows not as many would write it. If there was no one to infect with the malware, also no one would write it.
Re:PHP Sucks But I Like It by derefr on Tuesday April 10, 2012 @08:30PM (#3825268)
True, I suppose: if PHP were invented today, I imagine the pitch would be something like "it's the Dropbox of web applications: you just put files in a directory and they run."

(...on that note, I just realized how useful it would be if Dropbox's Public folder executed PHP.)

Re:PHP Sucks But I Like It by slurgfest on Wednesday April 11, 2012 @12:44AM (#3825964)
When there are so many cases where it fails, mysteriously and/or silently, you really cannot say it "just works".
Re:PHP Sucks But I Like It by aneth on Tuesday April 10, 2012 @11:14PM (#3825749)
Life is filled with simple, easy, cheap, popular paths that lead to ruin. PHPs initial simplicity does not make it a good choice.

Looking for happiness? Heroine "just works".

Hungry and poor? Eating McDonald's three meals a day is cheap and easy.

Re:PHP Sucks But I Like It by kamaal on Tuesday April 10, 2012 @11:24PM (#3825770)
Exactly that is why both Heroine and McDonald's sell.

It might sound scary. But in reality 'merit' is not the only motivating factor for adoption of anything.