Why Php sucks (and I still use it)

  • Php is slow, not just slow, but really slow. A simple benchmark runs in 1 milisecond in C. It takes 2 miliseconds for .Net. Python takes 600 miliseconds for instead of a native assembly language or jit-ted language it is an interpreted language. But Php, even though it also is an interpreted language and hasn’t got the enourmous object overhead Python has got it still takes 12000 miliseconds, that are 12 seconds.
  • Stupid work arounds, for Php itself is rather slow you got to rely as much as you can on function calls instead of doing anything yourself. It is for instance faster to load a list by deserializing a string than just reading line by line through a file although the deserialization would be way faster if both methods would be implemented nativly. Another little issue here is that most very quick functions in Php are only available in the newer versions (eg. file_set_contents), this requires you to add an if statement with a home made implementation of the function which usualy is slower by a factor of 10. You can choose to use an alternative way which doesn’t exactly implements the functions of the function you require to use but still does the job for the circumstance (better) (eg. not rewriting file_put_contents when it isn’t available when you want to streamingly write data to a file but rather call fwrite a few times which gets rid of having the whole file in the memory in a string at a time.
  • State less Although the Http protocol is a stateless protocol that doesn’t have to mean that a server side scripting framework should be stateless too. Although Php attempts to become statefull by using a session implementation by serializing a session array on the harddisk for every session this isn’t very efficient. Even one global array that persists between requests would result in such a performance boost. Not only for it doesn’t require file reads, writes, serialization and deserialization (and optionaly queries when you don’t like the php session system), but also for it would allow you to store that little bit of important cache between sessions that otherwise would have needed to be read, deserialized, serialized and written again, for every mere page view!
    Allowing such a persistant array however poses a security risk in the way Php works at the moment. They should add contexts to allow one instance of apache on which mod_php runs to execute files in different context, each with its own settings (and persistant data).
  • There is no satisfying solution in Php For every single common issue in Php there is no simple solution, that works perfectly or even reasonbly well.
    Take for instance templates. There are basicly a few ways to handle templates in Php. Usualy it comes down to either caching .php-scripts which are than executed as smarty does, or using a class for every major template section where every function fetches a template bit. In both these methods executing Php code is required to just only replace a certain tag with an replacement. Php has been designed to do a lot more than that and contains a lot of overhead during interpretation. Using str_replace‘s is a lot faster than a php block inline or even using instring php variables ("Example: {$example}"). The second way using classes and functions is even worse for the whole class and all functions first need to be loaded in the memory and basicly are a lot slower.
    The proper way to use templates is streaminly inputting and replacing tags with their values and outputting it. This isn’t possible for php is slow and loading the whole template in a string is even faster.

The only reason why I still use Php is for it is just the number one supported server side scripting language.

Why is world wide web not fair?

5 thoughts on “Why Php sucks (and I still use it)”

  1. despite the over negative view on php, it still can serves you, and there are many ways to make your code faster, and php now have caching in memory using apc, which by it self doubles the speed of php files processing…

    although i agree that php is not the optimal solution for enterprise business, but still can do it if u want to!
    plus it is an easy language… 🙂

  2. Hi Annon,

    PHP certainly serves me. If it wouldn’t be PHP but Python or Ruby which became the big language in webapplications they would have just served me better.

    There are, offcourse, workarounds, but they are ugly. You don’t want to use memcached or similar — you just want to have shared variables in the language itself without bothering about it, for instance. That there are so many extensions to PHP that make PHP faster (and why they aren’t included in PHP itself) is a clear sign that PHP could be faster by itself, but isn’t.

    I still wonder what the difference between enterprise and non-enterprise is.

    PHP can work. YouTube has been build with PHP.

    I’d just rather work with something else.

    (PHP is a very ugly and difficult language in some parts — eg. referencing)

  3. Yes, PHP suck,.. I use it,.. but it sucks!! really sucks!.. if you don’t use a framework (ej: Symfony, Zend, etc) sucks more,.. Sessions have a magic rare behaviour, OOP?? LOL… is simply based on a bunch of functions,… variables?? LOL, magic methods? there are just official workarounds, debugers / IDE.. you have to use 5 tools at least to reach 10% of the IDE of other languajes… I got a certification in php but is a pain in the ass doing big project with it…

    ASP.NET, Java, FLEX are much better…

Leave a Reply

Your email address will not be published.