SitePoint Sponsor

User Tag List

Page 1 of 8 12345 ... LastLast
Results 1 to 25 of 190

Hybrid View

  1. #1
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Could someone tell me why Java is faster than PHP

    I've been doing a lot of reading because of Harry Fuecks Pro PHP Rant
    In my reading, I tripped up on something.
    George Schnossnagle says here that he believes Java is faster than PHP.

    Notice how PHP being naturally slower than Java (something I believe to be true) comes in last?
    I always believed so too because (don't laugh)
    1. Java is used in Enterprise systems so it must be fast
    2. I thought because Java is compiled .... it would be faster.

    Well after doing a little research over at wikipedia
    I found this.

    This is achieved by most Java compilers by compiling the Java language code "halfway" to bytecode (specifically Java bytecode) —simplified machine instructions specific to the Java platform. The code is then run on a virtual machine (VM), a program written in native code on the host hardware that interprets and executes generic Java bytecode.
    Apparently compiled Java bytecode is interpreted too (just like PHP) so what makes Java faster than PHP?

    Is it the compiler or JVM runtime incorporated into J2EE (am I throwing around words I do not understand?)

    I really would like to know the answer to this.

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Two things. JavaVM's are developed by sun, who have brainpower (and shiny goldpieces) enough to make blindingly fast interpreters. And they have spend a long time doing it.
    Second, PHP compiles to bytecode on each request. This takes time. Further, since java bytecode is compiled in advance, the compiler can afford to optimize the bytecode.

    Additionally, PHP lives on a pper-request basis, where java servlets are kept in memory between requests.

  3. #3
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken
    Second, PHP compiles to bytecode on each request.
    I didn't know there was any compilation going on with PHP at all. I checked that out and found this
    That is really good to know.


    I read this article and a couple of others ... here's a quote.
    Faster is a non-starter, because Java is not so much faster than PHP that it makes much of a difference.
    What it seems like to me, is that Java isn't that much faster than PHP (if it is indeed faster).


    PHP's interpreter does not use less memory that a VM for java.
    I can't speak on this, because all my knowledge about this is theory (I programmed in Java a long time ago). However, it seems that Java loads a lot of stuff into main memory to run as quickly as it does and PHP doesn't use as much memory. Whether this is significant enough is probably dependent on your server right?


    It's a hell of a lot easier to build scalable PHP apps than it is scalable java apps.
    Maybe in an alternate universe? But certainly not this one
    I'm reading "Moving to ASP.NET Web Development with VB.NET" by Harris and Mac Donald. I don't code in VB.NET, but there was a big chapter on scaling Web applications that caught my eye. What they say in the book is borne out by George's ideas in my first post. The design and architecture of the web app affect scalability a WHOLE lot more than the individual language. Yes? No? maybe?

  4. #4
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ikeo
    I didn't know there was any compilation going on with PHP at all ... That is really good to know.
    Yes. An opcode-cache can boost performance quite a bit. I'll recommend you look at PECL::APC.

    Quote Originally Posted by ikeo
    What it seems like to me, is that Java isn't that much faster than PHP (if it is indeed faster).
    I think it depends a lot on the type of application, you're writing. If you are rendering 3d graphics, java probably beats the *** out of PHP. Webapps on the other hand, aren't cpu-heavy - it's a lot of i/o, and switching between i/o and cpu bursts. Theese things are more dependent on the OS than the interpreter, so the result are probably much the same for both.

    Quote Originally Posted by ikeo
    However, it seems that Java loads a lot of stuff into main memory to run as quickly as it does and PHP doesn't use as much memory. Whether this is significant enough is probably dependent on your server right?
    I'm guessing here, but I would suppose that the same VM can stay alive for ever, like a deamon. It's comparable to apache having to start up before PHP can be served.

    Quote Originally Posted by ikeo
    The design and architecture of the web app affect scalability a WHOLE lot more than the individual language. Yes? No? maybe?
    That's my view too. And java comes with a thorugh and very clever framework fo classes, which makes it much easier to write large scale apps. Java's framework may be a killer for beginners, but it's really valuable when you need to write bigger stuff. PHP on the other hand, is easily accesible, but doesn't help you much after a certain point.

  5. #5
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it depends a lot on the type of application, you're writing. If you are rendering 3d graphics, java probably beats the *** out of PHP. Webapps on the other hand, aren't cpu-heavy - it's a lot of i/o, and switching between i/o and cpu bursts. Theese things are more dependent on the OS than the interpreter, so the result are probably much the same for both.
    He He ... I wonder who would actually write a 3D graphics app in PHP? :P
    I get your point though.

    That's my view too. And java comes with a thorugh and very clever framework fo classes, which makes it much easier to write large scale apps. Java's framework may be a killer for beginners, but it's really valuable when you need to write bigger stuff. PHP on the other hand, is easily accesible, but doesn't help you much after a certain point.
    Okay, so I'm not crazy and all this reading is making me a little bit knowledgeable. I agree with you about PHP though. I wrote this website from scratch in PHP. Don't be deceived by the 2 or 3 pages it has, the CMS behind it is almost 3 or 4 times as big. It started out fine, but now it has become really tedious to use PHP to code it, and I don't even think using OOP would really help. I'm actually thinking about rewriting the whole thing in .NET.

  6. #6
    SitePoint Addict
    Join Date
    May 2005
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Prove that Java is "faster" than PHP in the general sense. "I think PHP is faster because of x" or "I think java is faster because of Y" doesn't work. Make two applications that run similiar logic and test them by sending several hundred simultaneous requests at each. Come back and report the results.

    In my experience, Java is slower than PHP for the stuff that you should be using PHP for as long as you're using an opcode cache. Even without the opcode cache, PHP frequently beat out most of the Java stuff anyway.

    And, no, simple "create x thousand variables and echo the output" type of scripts don't work. Why? Because that blatently ignores real world usage scenerios, namely the fact that a whole hell of a lot of the code that you use in PHP is actually mapped directly to C function calls, which is almost guaranteed to be faster than the java equivilents. Try doing something useful and then come back and say that Java is "faster" than PHP.

    There are also scalability issues to consider. It's a hell of a lot easier to build scalable PHP apps than it is scalable java apps.

  7. #7
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Etnu
    There are also scalability issues to consider. It's a hell of a lot easier to build scalable PHP apps than it is scalable java apps.
    ?

  8. #8
    SitePoint Member
    Join Date
    May 2003
    Location
    Laval
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Java is probably faster but you also have to look at the amount of resource it uses to be faster, ie: RAM.

    In my experience, Java runs faster but uses more memory. However it provides stateful execution through servlets. Use the right tool for the right job.

  9. #9
    SitePoint Addict
    Join Date
    May 2005
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken
    ?
    Java's startup cost means that you'll usually leave the process around and serve requests through that single process (the typical "application server" model). PHP's startup cost is extremely low, and the standard setup is to simply toss more instances of apache at the problem. As traffic increases, add more servers. It's pretty much infinitely scalable.

    Quote Originally Posted by Selkirk
    The Java VM is more advanced than the PHP VM. Read about fast garbage collection and Just In Time Compilation.

    One thing, though. All that JIT compilation, zillions of classes to load and shared state caches to warm up show up when you are loading a java desktop app -- Slow. This doesn't matter so much on a server, where you are running the same code over and over all the time and you never shut down the JVM.
    Fast garbage collection is meaningless when you simply toss away the entire app context at the end of the request (the way that you build PHP apps). PHP's garbage collection is actually pretty terrible, but it doesn't matter because you just toss it all out at the end of the request.

    JIT compilation does not make a web app faster. It can (theoretically) help improve the speed of a desktop app or server process. In practice, it usually performs worse than statically compiled apps (e.g. C). Web apps startup and tear down every request in the PHP model, so it doesn't matter.

    PHP's interpreter does not use less memory that a VM for java.
    In most instances it does. A typical command-line PHP app uses about 4 MB of RAM. An apache thread running the PHP interpreter will usually eat 6-12MB.

    Java as a language runs...much faster than php does.
    Prove it.

    Maybe in an alternate universe? But certainly not this one.
    How to scale PHP:

    Install app on more servers.

    I work with PHP code every day that deals with hundreds of requests per second. The scalability problems are always on the database end, not on the application end. If you want the app to handle a heavier load, you simply add more hardware 99% of the time. You can't just throw more hardware at a java app to solve the scalability problem. No, PHP isn't made out of magic and butterflies, but this is one area that scripting languages really shine.

    The idea that PHP's type hinting in some way makes apps *harder* or that it's a *problem* is just laughable. Dynamically typed languages have many advantages that statically typed ones do not. Data type indicates absolutely nothing about a variable. Use sensible variable names and document your code or it'll be hard to use. Forcing something as archaic as static typing on web development slows development cycles painfully.

    No, PHP is never going to be good as a daemon process. That's just cold hard truth. PHP excels as a web app language and as a general-purpose scripting language. It can replace perl for everything and everything else for web apps, but it'll never replace C when it comes to high performance daemon processes. Nobody's ever going to write a web server in PHP.

    EVERY language is "compiled". The difference is with regards to what it's compiled to.

    Java is compiled to java byte code which the JRE maps to machine instructions to perform tasks.

    PHP is compiled to PHP byte code which the PHP runtime maps to machine instructions to perform tasks.

    C code is compiled to machine instructions to perform tasks.

    C# code is compiled to CLI bytecode which the .net (or mono, or whatever) runtime (CLR) maps to machine instructions to perform tasks.

    What affects speed is when that compilation occurs. In PHP, compilation is done at run time (unless you're using an opcode cache). In other languages, it's done at build time.

    You can't really do the same in PHP, although you can use things like memcached to do some of them.

  10. #10
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Etnu
    Nobody's ever going to write a web server in PHP.
    Incidentally ... http://nanoweb.si.kz/

  11. #11
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree with you mostly but I want to gain a better understanding of some of your points.

    PHP's garbage collection is actually pretty terrible, but it doesn't matter because you just toss it all out at the end of the request.
    Can you prove this.


    JIT compilation does not make a web app faster. It can (theoretically) help improve the speed of a desktop app or server process. In practice, it usually performs worse than statically compiled apps (e.g. C). Web apps startup and tear down every request in the PHP model, so it doesn't matter.
    I've done some reading on this, and from what I understand JIT would help Java perform better than PHP because PHP is interpreted (after being compiled to Zend opcode).

    The idea that PHP's type hinting in some way makes apps *harder* or that it's a *problem* is just laughable. Dynamically typed languages have many advantages that statically typed ones do not. Data type indicates absolutely nothing about a variable. Use sensible variable names and document your code or it'll be hard to use. Forcing something as archaic as static typing on web development slows development cycles painfully.
    read this and let me know what you think

  12. #12
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ikeo
    PHP's garbage collection is actually pretty terrible
    Can you prove this.
    PHP uses a simple, naive reference counting algorithm for garbage collection. The link discusses the pros and cons of that.

  13. #13
    SitePoint Addict
    Join Date
    May 2005
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ikeo
    Can you prove this.
    Sure, just run a test that loops through infinitely and allocate / free memory (drop refcounts using null assignment), and notice how memory doesn't get freed very quickly. There are also many memory leaks that create all sorts of problems. In a web app, it really doesn't matter (the context only lives for a fraction of a second), but in a daemon it's a killer. This is a known limitation of the PHP engine, and it's not likely something that's going to be fixed anytime in the near term.

    I've done some reading on this, and from what I understand JIT would help Java perform better than PHP because PHP is interpreted (after being compiled to Zend opcode).

    read this and let me know what you think
    Like I said, in theory a JRE should be able to run faster, but in practice it doesn't. The main reason is because of all the extra overhead that the JRE has to carry around with it throughout the process.

    What the hell are you even talking about? In java any code that becomes "hot" will be compiled to native code. Whether that code is running a web application or desktop app simply doesn't matter.
    Because the time required to compile to native code is unacceptable in the context of a web app. JIT is nice in theory, but in practice it never lives up to it's expectations. That's why we're seeing emergence of things like compile on install, like what you get with .Net.

    google.com - Anybody that denies that Java as a language is faster than PHP is a mindless fan-boy of PHP. ...hell try writing any NON-TRIVIAL algorithm in PHP and Java and see which which does better. PHP can solve some of its performance problems by outsourcing its work to C via an extension though. PHP is just not in the same class as Java, compare it to Perl, Python etc.
    Google uses Java for some of their apps (and python, and perl, and, from what i've been told, even some PHP), but their search engine is most certainly not built in Java. Yahoo, however (which gets much more traffic than google on a daily basis) is mostly built on PHP (although extensions are used...extensively). Yes, on a straight algorithm vs. algorithm basis, Java will beat PHP in most circumstances -- but anybody who's actually developed a real application knows that you can't use that as a basis for comparison.

    Sure they have advantages...one of the advantages NOT being scalability. And...hmm..call me crazy but I'd imagine that a variables Data type would indicate something namely its data-type =).
    If you don't think PHP applications are scalable, you're just plain wrong. Wikipedia, yahoo, flickr, etc. -- all built with PHP. I work with large scale, high performance, extremely high scalability systems every day, and scripting languages have a huge advantage here due to the fact that you can always just toss more instances at the problem. It works every time. PHP just happens to be better than most because it runs faster than the other popular scripting languages.

    Again, what does data type tell me about an object? Absolutely nothing. In fact, it can be a hindrance because now when I want to change my data type later, I'm stuck having to manually go through my code to adjust.

    Statically typed languages have to resort to nasty hacks like generics to solve the problem.

    Adding typing information to variable names makes things really ugly. Furthermore if you have to add typing information to the variable names and/or document how does this imply less work?
    I never said "add typing information". I said "use sensible variable names". That means names like "PlayerName" or "NumberOfIterations" or "TimeToLive". You could do something like this in a statically typed language:

    void StartTimer(int ttl);
    void StartTimer(time_t ttl);
    void StartTimer(float ttl);

    or, perhaps:

    template<typename T> void StartTimer(T ttl); (assuming you're using a statically typed language that has actually at least implemented generics, of course...)

    etc.

    In php, you'd never have to change that function signature.

    If you have a case where you REALLY think that the type of data requested is going to be non-obvious (and you can't be bothered to add comments to the function signature), PHP supports type hinting:

    function CompareTwoObjs(MyObj $Obj1, MyObj $Obj2);

    as well as various functions for comparing data types.

    Again, no FORCING of static typing on anybody.

    Have you actually worked with java web applications AT ALL?
    Yes. And I don't deal with apps that just run on one server. The apps I write are built to be cross colo, multi-server applications designed to handle millions of unique visitors every month. I can say with absolute certainty that what we do where I work gets more traffic than what you do where you work. You CAN'T just scale a java app by throwing more hardware at it, but time and time again it's been shown that you can do that with many PHP apps (not all, of course, since database dependencies and such can bite you, but there are plenty that do just that).

    Large web applications have thousands and thousands of source files being worked on by many people....there is no sensible way to manage this with PHP.
    You don't manage source with PHP, you manage it with CVS (or SVN or Perforce, if you prefer). I can assure you that the thousands of PHP source files that the company I work for has in our CVS repository work just fine for us.

    don't see how a platform that has "pretty terrible" garbage collection can possibly excel as a general-purpose scripting language. "General-purpose" means that you may not be dealing with short-lived requests and environments that are being tossed out rapidly.
    You're confusing general purpose language with general purpose *SCRIPTING* language. Java, C, and C++ are general purpose languages. When I say scripts I'm talking about scripts in the literal sense -- bits of code that perform simple, quick tasks, then exit. PHP serves as a fine replacement for Perl or Bash in almost all cases.

    My personal opinion is that the lack of namespaces in PHP makes encapsulation at a library-level difficult and discourages the development and sharing of generic classes and class libraries.
    Yes, PHP's lack of namespaces is annoying, but it's hardly as crippling as some people make it sound. C (NOT C++!) doesn't support namespaces either, but it's used by thousands of developers around the world on thousands of projects (and is much older than any of the languages being discussed).

    [offtopic]
    Actually, I've seen it stated that Ruby scripts are currently not compiled to bytecode/machine language, but are converted into an abstract syntax tree and interpreted. So, it could be argued that Ruby isn't compiled.
    a rose by any other name...The compilation method differs from others, but it's still a case of converting a language into a simplified representation and then passing it into a machine that can interpret those commands (directly to the processor, into a VM, etc.) [/offtopic]

    as memory is so cheap
    Memory is only "cheap" under a few circumstances. If you're dealing with sunfires or such, then adding more ram is generally not a big deal, but that type of hardware is so overpriced as a whole that it really doesn't make the RAM "cheap". To achieve the high levels of scalability demanded by many of today's web sites (e.g. google, yahoo, etc.), you're dealing with a commodity hardware paradigm. 2GB or 4GB of RAM is fairly cheap, but most of these machines are limited to 4 or 8 memory banks, and RAM is exponetially more expensive the larger your modules are. There's very little sense in putting 16GB of RAM into a box like this when that extra 12GB cost you twice as much as it would to add another server. That's why they don't do it.

    I'm not sure what you are talking about here, explain?
    __autoload + auto_prepend_file directive can make it so that you never really have to worry about where your classes come from.

    PHP's arrays are not universally loved.
    The only real case where they cause problems tends to be when you need to do array merges, though. PHP's other conventions make it so that it's an ideal system. For most stuff that you'd use PHP for, maps make much more sense than arrays. I wouldn't be opposed to seeing a purely indexed array added, but I'd also be willing to bet that it'd get very, very little use.

    Quote Originally Posted by bonefry
    For those who say Java uses a lot of memory ... think about mobile applications.
    Oh, Java does use a lot of memory on mobile applications. That's why writing mobile apps is such a pain in the butt. The ONLY reason for Java's success on mobile devices is because writing portable C code for what is literally thousands of different architectures would be nearly impossible.

    JAVA beats the living crap out of PHP, when it comes to performance, for the following reasons:

    1) The Hotspot JVM knows about "adaptive optimizations" ... something that even the .NET CLR doesn't have yet
    And, again, something that doesn't matter to PHP because it's tearing down the app every view.

    2) PHP, being so crapy, is recompiled at every request, so that Zend can make a living
    Or you can just do what everyone who knows anything about PHP does and use APC.

    3) The cost of a new process is higher than the cost of a new thread
    Not by much on linux or freeBSD, and the overhead of locking usually far outweighs the overhead of extra processes. Threading is usually only advantageous when you need to do a lot of inter-process communication on these systems. Aside from that, PHP *IS* thread safe (at least in all the core libraries, some extensions aren't), and works perfectly fine with apache's MPMs.

    4) The JAVA language can be optimized very efficiently because it is a static language
    In theory, yes, in practice it makes very little difference for the types of applications you'd use PHP for. Yes, Java would trounce PHP-GTK for desktop development, and Java would smoke PHP for long-lived server processes, but otherwise it makes little to no difference.

    5) A LAMP setup doesn't have stuff like connection-pooling by default
    Lots of things don't exist by default.

    For those who say that PHP is more scalable that JAVA ... PHP is scalable because of its mediocrity
    Uhm...right.
    ... and tell me ... what infrastructure does PHP provide for distributed applications ?
    Are you talking about distributed as in load balancing or distributed as in package distribution? For the former, it doesn't need it, and for the latter you've got PEAR, PECL, or, well, any package management utility, since PHP doesn't require any kind of application registration or other such nonsense. You copy files to where they need to go and you're done.

    Anyone that says otherwise is clearly wrong, ignorant or religios about it.
    Except for when they're right. Web sites using PHP (big ones like Yahoo and Wikipedia) continually demonstrate lower hardware costs than Java based ones (Amazon being the nearest compatable site in terms of size off the top of my head). If Java is superior in performance, then why doesn't that show up in practice? You could possibly argue that Yahoo and Wikipedia have far better engineers than Amazon, but I'm pretty familiar with people working at these organizations and I can assure you that it isn't the case.

    This thread is useless as it clearly leads to a flamewar ... because of fan-boys that can't accept the limitations of a scripting language ... and thus they bash a technology they do not use or know.
    If you want productivity, then PHP may be the answer for you, but if you want performance ... with PHP it is like looking against the SUN
    How about the fan-boys that can't accept the fact that a scripting language can trounce a compiled language, even when the evidence is right there in front of them? No, in the "general sense" PHP isn't faster than Java, but for the things you use PHP for, it is.

    In fact, PHP cannot scale too well precisely because of its shared-nothing architecture
    You've got that completely backwards, friend. If you actually want to explain why you don't believe this to be true, go ahead, but anybody who's actually dealt with situations where hundreds of requests per second are being thrown at an app can tell you that the "shared nothing" architecture works like a dream.

    Why wouldn't they? Part of what makes a application scalable is its ability to deal with large development teams, large code bases etc. Which language used clearly effects this...
    Large development teams always lead to slow development. You break your project up into small, managable teams and put everything under source control.

    Your point is just myopic. Please look at what it takes to implement a regular expression engine (and regular expressions are used ALLLL over the place in web apps). When you start writing non-trivial web applications you'll find that there are no longer PHP extensions to do all the hard work for you.
    I write plenty of "non-trivial" web applications, and, while there are certainly some things that PHP doesn't do well, It's pretty rare to encounter a situation where there isn't already an extension to do the hard work for you. The only cases where I can recall in recent memory where there weren't good solutions in PHP was when I had to interface with external services that were being provided through some low level system (shared memory transports and the like). Most people on this forum will NEVER have to deal with these types of issues.

    Well the site clearly states why php should have namespaces...but they don't offer a solution they offer ideas on how a solution would look like. I mean they clearly state what they are doing is for demonstration. Namespaces are the sorts of things that need to be added to the language itself.
    Actually, they do offer a solution (and it works), it just hasn't been made a part of PHP yet due to some performance issues that are still being sorted out. Most likely no decision will be finalized until PHP6 and all the unicode changes have been finalized.

    But just one question ... is Java and PHP comparable?
    For some applications (we're discussing web apps, specifically here)

    similerly is it fare to compare Zend Vs. SUN?
    Not at all.

    The only thing that is obvious is that you have no experience with modern statically-typed languages, and are speaking from ignorance. Static typing makes renaming classes, methods, constants, etc. easier because tools such as IDEs can perform static analysis on your code and know 100% that all references have been updated.
    Except that you rarely, if ever, control all the code that you're working with. It's the old "binary compatability" problem. I'd love it if there was an IDE capable of actually loading 1000+ files at once and doing find and replace on them all.

    In Eclipse you select an identifier, hit ALT-R, type in the new name, and you are done. ALL references in your project are updated automatically. No regular expression search and replaces required. And this is possible precisely because of the information that static typing provides the tool.
    Actually, this tool does use regexes to update. It just changes the source code. Just because you don't have to manually type in a regex doesn't mean that's not what's happening.

    Dynamically typed languages make such refactorings much more difficult.
    They would, if it weren't for the fact that you don't need to do it in the first place because you don't declare type.

    Since PHP (and other dynamic languages) allows you to store the names of classes, methods, etc. as strings and invoke them that way even the most inclusive regex can't gaurantee that all references are updated.
    Nope, and in Java you can't do that AT ALL (well, you kind of can with reflection, but that has the same limitations that you just mentioned). What's your point?

    Simply put, if you have never used a modern IDE with a statically typed language such as C# or Java then you have no idea what static typing makes possible regarding tool support.
    Because you *DON'T NEED IT* in PHP. The most useful tool that most IDEs provide is autocomplete (intellisense, if you will) and module / function / class heirarchy management. Both eclipse and zend studio do this just fine for PHP.

    Why is it some of the largest enterprise web applications are written in Java? Power and Scalabilty! Look at Ebay, UPS, Fedex, PetsMart (I could go on for ever) .... I have yet to see an honest to god enterprise level application written in PHP ...... PLEASE show me one!
    Wikipedia, Yahoo, etc...all mentioned already (and lets not even get into all the usage of C/C++, perl, and python). Maybe you should have read the whole thread before you commented. Java got sold to enterprise customers because Sun marketing people pushed it at the same time that they were pushing hardware, so it caught on.

    WHAT STARTUP COSTS!
    Nobody's discussing money here. We're talking about startup cost in the performance sense. Again, read the whole thread.

    PHP is fine for this type stuff, it's easy to write (usually) and works fast enough. BUT when I need a massive app that has to be able to do anything I need in any way shape or form I go to Java.
    And this ENTIRE THREAD has been about web apps. Nobody's trying to argue that PHP is faster than Java in the traditional application space. I'd also question the wisdom of ever creating a "massive app", in any language, on any platform, for any purpose.

    There is one reason it should not be...Zend wants to make Money off its stupid "Zend Platform". This is one reason I dont' use PHP much....to get nice features (that are stable) you have to get the Zend Platform.
    Funny, I've never used Zend's products outside of the evaluation period (some of their tools are alright, most of them aren't really worth the money in my opinion), and I can't think of a single "nice feature" that they have that I don't currently have in a stable form.

  14. #14
    SitePoint Zealot DerelictMan's Avatar
    Join Date
    Oct 2005
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Etnu
    Dynamically typed languages have many advantages that statically typed ones do not.
    And vice versa...
    Data type indicates absolutely nothing about a variable.
    Nothing? Of course there are many intelligent people on both sides of the static vs. dynamic typing issue, but usually the argument made by the pro-dynamic typing people is that static typing does bring benefits, but it also brings costs and they feel the costs outweight the benefits. But I don't usually see too many people who say that data types provide no information at all, a statement that seems a bit hyperbolic to me.

    I'll agree that in simple web apps it probably doesn't make much of a difference whether you're dealing with an integer 1, a string "1", or a double 1.000. Primitive types can be fairly easily coverted to other primitive types without losing too much information. However, in object-oriented code I've found data type information to be highly useful. Consider two random classes that you use in your PHP code. It's not very likely that an instance of one of your classes could be converted to an instance of another... the class of a particular variable is very important, and indicates what it is and what can be done with it (what methods can be called, etc.). It seems odd to say that this information doesn't matter.
    Use sensible variable names and document your code or it'll be hard to use.
    For me, one of the advantages (and yes, I see disadvantages too) of static typing in an OO language is documentation. It's immensely useful to know without a doubt what type of objects are required as parameters on a method, and what type of object I'm going to be getting back. I've found in my and other's dynamically typed OO code, there is sometimes a tendency to give object instances longer and more cumbersome names in an effort to make it clear what class the instance belongs to. This is, in a way, a type of Hungarian notation for types, and I think most people here would agree that this is a Bad Thing. Sure, you don't have to do this; you can pick the same names as you would in a statically typed language, but it sometimes makes it a little trickier to know what you're dealing with, especially if you have classes that are different but may contain a common subset of similar or the same method names.
    Forcing something as archaic as static typing on web development slows development cycles painfully.
    I think it depends on what style works for you. A counter argument to this is that it may slow initial development time, but it may improve maintenance time. You only write your app once, but you may be refactoring/maintaining it for a long time to come. The argument could be made that you should optimize for maintenance and not for the initial development time.

    As for me, I see advantages and disadvantages to both. For simple tasks, static typing can be onerous. For more complex ones, I feel it improves the ability to reflect on what the code is doing and it may improve maintenance. So, speaking for me personally, I don't necessarily prefer one over the other; they both very much have their uses.

    PHP excels as a web app language and as a general-purpose scripting language.
    You are being slightly inconsistent here. You say that PHP excels as a general-purpose scripting language. But earlier in your post you stated:
    Fast garbage collection is meaningless when you simply toss away the entire app context at the end of the request (the way that you build PHP apps). PHP's garbage collection is actually pretty terrible, but it doesn't matter because you just toss it all out at the end of the request.
    I don't see how a platform that has "pretty terrible" garbage collection can possibly excel as a general-purpose scripting language. "General-purpose" means that you may not be dealing with short-lived requests and environments that are being tossed out rapidly. I would argue that PHP does excel as a web app language but still has some improvements to be make before it can truly be "general-purpose".
    It can replace perl for everything
    I beg to differ. Perl most definitely has its warts, but it's still very useful for many tasks. PHP does not currently, and likely never will, have anything comparable to CPAN. You may find Perl the language ugly (although in many ways it is much more advanced than PHP: true block-level scoping, namespaces, closures and truly-anonymous code blocks, etc.), but there is an amazing selection of truly-useful reusable code available at CPAN for just about any task you can imagine. I've found that the same cannot be said for PHP. My personal opinion is that the lack of namespaces in PHP makes encapsulation at a library-level difficult and discourages the development and sharing of generic classes and class libraries.

    Disclaimer: I've been pretty down on PHP in this post. Before anyone gets the idea that I'm a "hater" let me state that I do think PHP has a sweet spot in certain types of applications, and I use it heavily where it makes sense. It just feel that this attitude of "PHP has nothing to learn from other platforms" holds it back, and that's a shame...

    Off Topic:

    EVERY language is "compiled".
    Actually, I've seen it stated that Ruby scripts are currently not compiled to bytecode/machine language, but are converted into an abstract syntax tree and interpreted. So, it could be argued that Ruby isn't compiled.

  15. #15
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    Edinburgh, Scotland
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Etnu
    EVERY language is "compiled".
    Even JavaScript? I seem to remember being told that scripting languages like JavaScript, VBScript and PHP were all interpreted languages.

    To try and answer the original post, the question is largely un-answerable by other people. If you have a specific situation, then get a Java expert and get a PHP expert, give them the same task and see who does the best job. While your at it, note who takes longer to complete the task, and which one requires the most server resources. Then change the spec and see who gets things sorted quickest. I make no predictions here, because it all depends on the task in question, and how you predict the future. If your task is complex and heavy-weight, and you expect to need to maintain it in the future, with a large team of developers, then I would suggest that you think of Java first.
    If you have a very small app, that will need little maintenance, and you know PHP yourself, then that is probably a better option, even if you can prove that Java runs faster.
    Throw away your Calculator -
    get instant results from www.calcResult.com

  16. #16
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by omnicity
    Even JavaScript? I seem to remember being told that scripting languages like JavaScript, VBScript and PHP were all interpreted languages.
    Some JavaScript implementations compile down to Java bytecode (and with a JIT VM some may end up as native code). Rhino does it I think.

  17. #17
    l º 0 º l silver trophybronze trophy lo0ol's Avatar
    Join Date
    Aug 2002
    Location
    Palo Alto
    Posts
    5,329
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Uh-oh. Something smells like burning.
    .
    Zach Holman
    good-tutorialsblogtwitterlast.fm

  18. #18
    SitePoint Wizard silver trophy rushiku's Avatar
    Join Date
    Dec 2003
    Location
    A van down by the river
    Posts
    2,056
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by lo0ol
    Uh-oh. Something smells like burning.
    Could this have been anything but a flame thread?

    up next: Who can tell me why Apple computers are better than PCs?

    As to the topic:
    Java is faster because it's named after coffee, coffee has caffeine, caffeine is a stimulant, stimulants make you feel like you're going faster.
    P-H-P kinda looks like p-o-o-p, if you squint really hard; poop isn't very fast at all.

  19. #19
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The Java VM is more advanced than the PHP VM. Read about fast garbage collection and Just In Time Compilation.

    One thing, though. All that JIT compilation, zillions of classes to load and shared state caches to warm up show up when you are loading a java desktop app -- Slow. This doesn't matter so much on a server, where you are running the same code over and over all the time and you never shut down the JVM.

  20. #20
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Selkirk
    The Java VM is more advanced than the PHP VM
    Semantic question here but ....
    Is it really called the PHP Virtual Machine or is it the PHP runtime?
    Would those be one and the same thing?

  21. #21
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Pittsburgh, Los Angeles
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Apparently compiled Java bytecode is interpreted too (just like PHP) so what makes Java faster than PHP?
    Java isn't "interpreted" in the same sense that php is, java's VM is much more sophisticated than what PHP offers. Java hasn't been an "interpreted language" for a long time (I forgot which version changed its status though). Anyhow java as things like a Hot spot compiler, which will compile "hot stops" of the program to machine code.
    Theoretically its possible that this can make much better optimizations than when you say compile C to native code, as it has much more information about the system its running on.

    In my experience, Java runs faster but uses more memory. However it provides stateful execution through servlets. Use the right tool for the right job.
    Whats your basis for this claim? In a web environment java based applications work
    MUCH differently than php apps do. That is to say with servlets you can save things between requests...if you do this of course you'll use more memory. But you are using more meory because you are doing something different. Where as with php all memory allocated during a request is taken back. PHP's interpreter does not use less memory that a VM for java.
    PHP frequently beat out most of the Java stuff anyway
    If PHP is performing better than your java stuff then you dont' know how to write java.
    Java as a language runs...much faster than php does. Furthemore in a web environment you can make optimizations that you cannot make in php, where as any optimization you do with php is either a standard feature with servlets/jsp or can easily be done.
    It's a hell of a lot easier to build scalable PHP apps than it is scalable java apps.
    Maybe in an alternate universe? But certainly not this one.

  22. #22
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Pittsburgh, Los Angeles
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    However, it seems that Java loads a lot of stuff into main memory to run as quickly as it does and PHP doesn't use as much memory. Whether this is significant enough is probably dependent on your server right?
    It may be the case that java VMs use more "base" memory than the PHP interpreter I haven't really bothered to look as in either case its not very big. I was referring to the amount of memory your application will use. But this is a little hard to compare...but I have tested roughly how much memory is used by PHP objects vs Java objects and java does much better. Also even the PHP people note that Java is better at object allocation/collection and warn against pretending (namely PHP5) as if it is java.
    Webapps on the other hand, aren't cpu-heavy - it's a lot of i/o, and switching between i/o and cpu bursts. Theese things are more dependent on the OS than the interpreter, so the result are probably much the same for both.
    With java web technologies you can greatly reduce this load, by using in memory caches. You can't really do the same in PHP, although you can use things like memcached to do some of them. So this is only true when you app can't take advantage of any sort of caching logic.
    The design and architecture of the web app affect scalability a WHOLE lot more than the individual language. Yes? No? maybe?
    Sure, but the language and the technologies built on it effect how you design the application. With java (and .NET) there are standard web frameworks that have proven to be scalable, there is no such thing in PHP. Although I think Zend is working on some framework...I'd be really suprised if it did well. Even the lack of good IDEs for PHP effect its scalability. To me at least, PHP is just a templating language trying in the last couple of years to be something else. Its very good to use when you are writing a thin client over some database...but to write any real "business logic" in it seems silly.

  23. #23
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Snaily
    But this is a little hard to compare...but I have tested roughly how much memory is used by PHP objects vs Java objects and java does much better.
    This doesn't surprise me. OOP was an after thought in PHP 4 and Zend still haven't gotten it completely right in PHP 5.


    With java web technologies you can greatly reduce this load, by using in memory caches. You can't really do the same in PHP, although you can use things like memcached to do some of them. So this is only true when you app can't take advantage of any sort of caching logic.
    Lets not make this about J2EE vs PHP. Every one knows ... or should know (at least) that J2EE provides a bevy of tools and functionality for enterprise level web application development that PHP can only dream of at this point. (I'm agreeing with you.)


    Sure, but the language and the technologies built on it effect how you design the application. With java (and .NET) there are standard web frameworks that have proven to be scalable, there is no such thing in PHP. Although I think Zend is working on some framework...I'd be really suprised if it did well.
    Ehhhh ... kinda sorta. This one goes back to the fact that PHP wasn't designed to be an application language. I agree with you about the Framework and how it helps make ASP.NET and J2EE easier to scale. However Java (as a language) isn't more scalable than PHP. Java already has a framework that helps it scale. I'd like to see what PHP does with its framework in PHP6 before I make a judgement either way. Make no mistake, PHP can scale, but I think I can concede without controversy that Java and .NET frameworks make it easier to do.

    Even the lack of good IDEs for PHP effect its scalability. To me at least, PHP is just a templating language trying in the last couple of years to be something else. Its very good to use when you are writing a thin client over some database...but to write any real "business logic" in it seems silly.
    I agree up until the bolded part. Frameworks are available in PHP that make it very possible to write business logic in PHP .... WACT for example. And every man's definition of "silly" varies. Also (I hope someone else jumps in on this to offer an alternative viewpoint) but its my belief that PHP IDEs are just as plentiful, if not more common than Java IDEs.

  24. #24
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Pittsburgh, Los Angeles
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also (I hope someone else jumps in on this to offer an alternative viewpoint) but its my belief that PHP IDEs are just as plentiful, if not more common than Java IDEs.
    They are just as plentiful, but there are no where near in quality. I have used the ones that are suppose to be the best (Zend Studio, eclipse with php plugin etc) and can say I'd almost go "old school" and use emacs. I think PHP being "dymanically typed" has something to do with it...but in many cases more can be done. Where as products for java like Intellij are a pleasure to use. Although I will say I found Zend Studio's debugger to be decent
    However Java (as a language) isn't more scalable than PHP
    Actually, I think this is wrong. The two main issues that come to mind are that PHP lacks namespaces and that PHP is dymanically typed. The first I think most would agree with. With the second you can add comments to variables, methods etc to give hints about what they are suppose to be...but this is a bit hacky and usually developers get lazy with documentation. Also I'm aware of PHP5's "type hinting" in methods, but this only solves a few of the problems.

  25. #25
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Snaily
    They are just as plentiful, but there are no where near in quality. I have used the ones that are suppose to be the best (Zend Studio, eclipse with php plugin etc) and can say I'd almost go "old school" and use emacs. I think PHP being "dymanically typed" has something to do with it...but in many cases more can be done. Where as products for java like Intellij are a pleasure to use. Although I will say I found Zend Studio's debugger to be decent
    Debatable ... there's Komodo, PHPEdit, PHPDesigner (My new favorite), TSW Webcoder 2006 and tons more. I don't know much about Java IDEs so I can't speak to that. I do like Netbeans though.


    Actually, I think this is wrong. The two main issues that come to mind are that PHP lacks namespaces and that PHP is dymanically typed. The first I think most would agree with. With the second you can add comments to variables, methods etc to give hints about what they are suppose to be...but this is a bit hacky and usually developers get lazy with documentation. Also I'm aware of PHP5's "type hinting" in methods, but this only solves a few of the problems.
    I saw a post that made pointed out similar problems with PHP scalability
    Pretty brutal, but good points nonetheless. I really can't argue on this since my experience with scaling is pretty limited, so I have to concede on those points as well.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •