No PHP for big projects? Why not?

I read several posts where people stated (did not offer, did not discuss, did not offer) that PHP should not be used for large projects.

As the main PHP developer, I ask two questions:

  • What defines a "big project"?
  • Why not? What are the pitfalls of using PHP

I am launching a small group of developers, and I know from experience that quality, organization, documentation, commenting and encapsulation are our highest priority. We can develop excellent projects using our own framework and approach, but, nevertheless, I do not want to invest further if I spend my time.

Thoughts?

+53
php scalability
Dec 21 '08 at 23:42
source share
11 answers

I really hate it when people say that PHP is a terrible language, because you can write code that mixes presentation with logic or allows you to allow SQL injection. What you don’t have to do with the language at all is that the developer.

PHP turned out to be very scalable: Wikipedia is one of the largest and most popular sites on the Internet, and it runs PHP. Enough said?

There are many tools / libraries that give you the foundation for working, which makes it less likely that someone will write bad, less repairable code: see CakePHP, Symfony, PDO, Smarty, etc. etc. etc.

He got a bad rap because it is a language that has very low barriers to entry: it is free, you can get very cheap PHP hosting, there is better documentation , there are a lot of tutorials on the Internet, plus it makes a lot very simple (for example: open the URL and get the contents of the file: file('http://www.google.com'); ). This means that many newcomers picked it up and made very dodgy sites with it, but this will happen with any language that you choose as the first.

Working with a solid ORM framework (about 30 of the best SO questions about SO) and that will treat you well.

+80
Dec 22 '08 at 0:21
source share

Many people who say they don’t use it do say that they don’t use PHP 4. It comes down to this

you can write good code in any language

and

you can write bad code in any language

PHP can very often afford to get confused in spaghetti code libraries and make your "application" really just a series of scripts (see Moodle for a good example ...)

I think many of Do Not Use PHP for Big Things come from the fact that PHP is hacked from its original purpose: a template language. What I can understand, but there are many projects that prove that you can do this (Drupal, mediawiki, Facebook).

+29
Dec 21 '08 at 23:58
source share

There is no reason why you cannot use PHP for large projects. After all, Facebook is built on PHP. However, there will be problems, but there are problems with any major project.

What makes PHP so widespread is its low barrier to entry and cheap hosting. It works as an Apache extension, and you can just start coding. If you upgrade to other enterprise platforms such as .Net or Java, they have a much higher barrier to entry, but they also have a lot of infrastructure to help you build scalable applications.

For example, database abstraction in PHP is (imho) bitter. This is a specific provider. With MySQL, people tend to do things like:

 function get_users($surname) { mysql_query("select * from users where surname = '$surname'"); ... } 

which is bad for several reasons:

  • It makes poor use of the query cache;
  • It does not handle character escaping (which, of course, can be done with mysql_escape_string() , but you will be surprised how often people do not); and
  • It is fairly easy to code in such a way as to allow SQL injection attacks.

Personally, I prefer mysqli for all of the above reasons, but it has its own problems: namely, that using LONGTEXT fields breaks mysql and has been running since at least 2005, while there is still no fix (yes, I and some others raised an error )

Compare this to Java (which I'm more familiar with), and JPA or Ibatis are significantly better ORM solutions with higher startup costs, but they will help you across the enterprise.

Thus, you are not forbidden to do large projects in PHP. It is simply more difficult in that you have to work more and more independently to reproduce what other platforms offer you.

PHP + memcached / APC + beanstalkd goes a long way.

Oh, that is another problem: PHP does not support background processing or streaming processing. For this you need something else (or stand-alone scripts). If you use something else, why not use it for web content (e.g. Java, Ruby, .Net, etc.)?

+18
Dec 22 '08 at 0:00
source share

Since the question that I linked was deleted, I put it here:

Question




I made a compromise on another topic, calling PHP a terrible language, and it went down - voted like crazy. There are apparently a lot of people who love PHP.

So I'm truly curious. What am I missing? What makes PHP a good language?

Here are my reasons for not liking:

  • PHP has inconsistent naming of built-in and library functions. Predictable name patterns are important for any design.

  • PHP has inconsistent ordering of built-in function parameters, for example array_map vs. array_filter, which is annoying in simple cases and causes all kinds of unexpected behavior or worse.

  • PHP developers constantly condemn built-in functions and lower-level functions. A good example is that they are deprecated for omissions for functions. This created a nightmare for those who make, say, the callbacks function.

  • Lack of consideration during the redesign. The aforementioned deviation precluded the ability in many cases to provide default keyword values ​​for functions. They fixed it in PHP 5, but they refused to pass by reference in PHP 4!

  • Poor execution of namespaces (previously there were no namespaces). Now that there are namespaces, what do we use as a dereference symbol? Backslash! A character used universally for escaping, even in PHP!

  • Too wide an implicit type conversion leads to errors. I have no problem with implicit conversions, say, floating point to integer or vice versa. But PHP (the last time I checked) will happily try to magically convert an array to an integer.

  • Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms a lot easier. Poor support is unforgivable.

  • Functions are case insensitive. I have no idea what they think about it. A programming language is a way to define behavior for both the computer and the code reader without ambiguity. Case insensitivity introduces more ambiguity.

  • PHP encourages (practically requires) the interaction of processing with presentation. Yes, you can write PHP that doesn't, but it's actually easier to write code in the wrong way (in terms of sound design).

  • PHP performance is terrible without caching. Does anyone sell a commercial caching product for PHP? Oh look, PHP designers do.

Worst of all, PHP convinces people that building web applications is easy. And that really makes most of the effort much easier. But the fact is, creating a web application that is safe and effective is a very difficult task.

After making sure that many are involved in programming, PHP taught a whole subset of programmers bad habits and bad design. This gave them access to opportunities that they lack for safe use. This led to the PHP reputation being unsafe.

(However, I readily admit that PHP is no more or less secure than any other web programming language.)

What am I missing in PHP? I see an organically grown, poorly managed language mess that spawns poor programmers.

So convince me otherwise!




Best answer




I'll take a hit by responding to each of your markers

PHP has an inconsistent name for built-in and library functions. Predictable naming patterns are important in any design.

I love and hate this topic. Because inherently this problem is true. Why is the bi-word function shared with underscore and some not? Why do needle and senate parameters sometimes replace positions in the argument signature? That's funny. But in the end ... does it really matter? My intellisense and php.net IDE is just a browser browser, this is just not a big deal. Is this negative for PHP as a language? Yes. Does this interfere with my ability to be an effective programmer? No.

PHP developers constantly discount the built-in functions and lower level. Good example, when they are deprecated pass-by-reference for functions. This has created a nightmare for anyone who does, say, callback functions.

Personally, I think this is not very good. Aversion is necessary for the evolution of a language, especially one that has as much as PHP. PHP gets a lot of flacks to “simplify working with a bad programmer,” but at the same time, the PHP group also has problems when they try to remove silly constructs from the language, such as call forwarding -Help. Eliminating call forwarding over time was one of the best steps they have ever taken. There was no easier way for a novice developer to shoot in the foot than with this “feature.”

Lack of consideration during the redesign. The above exception eliminated the ability in many cases to provide default keyword values ​​for functions. They fixed it in PHP 5, but they are deprecated for forwarding in PHP 4!

I don’t think there is a general lack of attention at all, I think you just got stung by this particular change and stayed with a sour taste in your mouth. Language changes are often known for months, if not years earlier. A migration guide was provided for the transition from 4 to 5, and the differences in the version are indicated in the manual. Call time redirection was a terrible "function" and did not give the developer any expressive power that they could not get by other means. I'm glad he left (along with other shit, like magical quotes)

Poor execution of namespaces (previously there were no namespaces). Now, what are the namespaces that we use as a dereference symbol? Backslash! The character used is universal for escaping, even in PHP!

I have mixed feelings about this. Part of me thinks, “who cares, character escape doesn't matter outside the line anyway,” and part of me thinks “for sure they could use something better.” But could they? I do not know, I am not a developer for the Zend parser. Is this a huge oversight that before 5.3 PHP never had a namespace at all? Yes, absolutely.

Too wide an implicit type conversion leads to errors. I have no problem with implicit conversions, like float to integer or vice versa. But PHP (the last one I tested) will happily magically convert an array to an integer.

I think I don’t agree with how PHP does it, but I don’t agree that it makes the language “bad”. But ask me how much I want to sit on this topic and argue about weak versus strong typing. (PS I don’t do this at all). For the record: PHP will throw an E_WARNING level error when the type of the argument matters and cannot be resolved by force.

Poor recursion performance. Recursion is a fundamentally important tool for recording in any language; it can make complex algorithms a lot easier. Poor support is unforgivable.

PHP is the DSL for the web. I have been doing this full time for 8 years and may have used recursion 4 or 5 times, usually for some type of annoying directory or XML traversal. This is simply not the template that is often needed for web development. I do not condone slow performance, but this is an academic problem far more than a production problem. If you need really powerful recursive performance, PHP is no longer the language for you.

Functions are case insensitive. I have no idea what they were thinking about this one. A programming language is a way to specify behavior for both a computer and a code reader without ambiguity. Case insensitivity introduces more ambiguity.

I completely agree with this 100%.

PHP encourages (practically requires) connection processing with presentation. Yes, you can write PHP this is not so, but it’s actually easier to write the code in the wrong way (in terms of sound design).

* Hmmm, this topic sounds desperately familiar ...

But seriously, I find it wonderful that people will complain about a language that will absolutely 100% allow you to implement any output system that you want (only volumes and style of PHP templating systems speak about it) - OR - skip all that overhead and just output directly. This does not make PHP bad. This is part of what makes PHP good.

PHP performance is terrible without caching. Does anyone sell commercial product caching for PHP? Oh look, PHP designers do.

Do you mean bytecode caching (like an accelerator) or output caching?

If the first, then I really don't know how much I care about this topic. Accelerators are free and easy to start. We can argue about why it is not part of the language, but in the end, I don’t think it matters much.

If you're talking about output caching, I don't know what to tell you. ANY web project with significant traffic caching (e.g. seed podcast # 27). This is not a PHP specific issue.

All in all, I think you think PHP is a “bad” language in a very academic way. And in your previous post, you were probably rejected by people like me who use PHP to "do the job."




Second best answer




All your criticisms (and some others) are valid. You are allowed to and even expect to hate PHP.

But, again, it has some advantages:

  • All-local
  • Fast (especially using operation operations caches)
  • Huge community (and great documentation)
  • Work

Finally, you can overcome many, if not all, of the shortcomings by writing good code that you can write in any other language. You can write reliable, safe and good code, inflated in PHP, which will run faster many times and will be easier to place and scale than many alternatives.




Third Rating>




What am I missing in PHP? I see an organically grown, poorly managed language mess that spawns weak programmers.

Simple The fact that poor programmers are very protective of their language .;) PHP is easy to learn, much easier than alternatives, and once you know it, it is not entirely obvious: 1) what is with PHP, 2) how are the alternatives better, and 3) how to switch to and find out one of the alternatives.

And perhaps the fact that, what alternatives do people have? ASP? This has many problems on its own, due to the inability to run on most web servers (Apache), to some ridiculous and redesigned design options on your own (web forms? ViewState? AJAX, where your asynchronous requests are intercepted and run sequentially?) Rubin on rails? Well, perhaps, besides, how many web servers support it again? At the moment, it is not quite readily available. And it’s slow. So maybe PHP's “strength” is really such that there is no good alternative. At least that is why I always avoid any web programming. PHP sucks, and I'm not too keen on any of the alternatives either.

PHP has so many fundamental problems that it’s not even funny. Due to the lack of unicode support, to many implicit type conversions that often lead to unexpected security holes, to completely mixing up the presentation and ... everything else, or to the default database module that didn't (the last time I checked) parameterized queries . We are talking about a language made for two things: database access and HTML generation, and which is terrible for both.

It’s just an unpleasant mess, a language developed by people who are not qualified or able to develop a language .;)




+15
Dec 22 '08 at 0:00
source share

For me, the worst PHP sin is combining presentation with business logic. This does not mean that you cannot write it better, but it does not encourage you, and, if you like, it does not encourage you.

A large number of security vulnerabilities are also associated with PHP sites. I cannot prove that this is disproportionate (after all, many sites are written in PHP), but I suspect that it is. If I am right, then, since security vulnerabilities are a class of errors, I suspect that PHP sites are generally also more complex.

(I don’t think that pointing to several large sites and saying that they managed to do this in PHP is, by the way, any argument against this. It is a bit like cigarettes do not cause cancer, because the next door was smoked by the neighbors and survived to 100.)

+4
Dec 22 '08 at 0:07
source share

Check out this similar question - Can PHP handle enterprise level sites as well as Java .

Recupping - Facebook, Wikipedia, Yahoo.com, Digg, Flickr and many other giant sites run on PHP. If you've ever come close to making something from this caliber, you can still be sure that you can get there with PHP.

How supported, expandable, reliable, secure, and efficient applications will fully meet your requirements and are agnostic. In favor of PHP, however, it has very convenient tools for building web applications.

+2
Dec 22 '08 at 0:36
source share

For me, speaking of large or even huge projects, it (first of all) comes down to one word: Dependencies .

The problem with the scripting language is similar to everything in the world: the biggest advantage is the biggest flaw at the same time.

The biggest advantage is free and fast code. Just write a script and it will use it. No verbosity required, just code.

The biggest drawback is making sure that this script does not interfere with other scripts. Or better: change the old script to others. Are you sure that all the dependencies work according to your wishes?

This is not true for "normal" web page generation, whatever that means here. But we have a product based on some 500k lines of source code, with settings for clients consisting of an additional 100k lines of code. , / , - (, , ).

, , "" (, " " ), , PHP ( : ) .

+2
22 . '08 0:38
source share

- PHP , .

0
21 . '08 23:47
source share

.

. 5 , 85 -, , , , - , .

, . , PHP , , " " .

Thanks everyone!

0
22 . '08 6:04
source share

- PHP-, . , . . (_), ( ) .. , . , , . .

. -, PHP , , .

- . , OOP PHP 5 , ?

, , : . .

, , , ; , .

0
02 . '09 1:33
source share
0
29 '10 7:10
source share



All Articles