The biggest difference between Java and PHP for Web development is why it's so much more Java

Source: Internet
Author: User
Tags hhvm php open source project zend framework ruby on rails
The biggest difference between Java and PHP for Web development is why it's so much more Java

Reply content:

The biggest difference between Java and PHP for Web development is why it's so much more Java

Feel php to do the background of web development more, Segmentfault should be the background of PHP, Java to do the web background performance better, support more request per second, but the Java development cycle is long, iterative slow, but for small and medium-sized website, performance is never the key , PV does not reach tens of millions of, hundreds of millions of cases, how to rely on a small team to quickly iterate the product is the most critical. And as a Web backend, performance bottlenecks tend to be in db. Before Twitter was developed by Ruby, it was later changed to Java because the data was too big for the day (in fact it should be java+scala+clojure). For most Internet companies, the ability to iterate products quickly is the core of the enterprise's survival, and most of them are in the background of a mix of languages, not to mention simply PHP or java.
Technically, LAMP (linux+apache+mysql+php) is basically the Internet standard, PHP-based framwork significantly more.
PHP Company: N More small sites, such as Baidu, QQ, Facebook, of course, these companies also use Java
In Java: ebay, Ali, Twitter

Does PHP have a worse web application performance than Java? Take the query MySQL to get the result set and display the data on the page as an example to analyze. HTTP requests are handled by C-level programs such as Apache/nginx (Java's HTTP service uses Java-developed Tomcat, etc.), and PHP invokes a database-driven mysqlnd built into the PHP engine's C development ( Java is the Java development of the JDBC driver to operate MySQL, the logic of the query is the focus of the development of the C/D + + MySQL, and then put the return result set in the PHP array, after the string processing in the page output, the logic is not complex, PHP load is not large. It is worth noting that PHP's built-in library functions are all implemented using C, while Java's core runtime class library Rt.jar is implemented using Java.

In some of the CLI under the pressure test, because there are a large number of loops, it is easy to trigger the Java JIT hot-spot compilation, Java computing performance to rise to the level of C, such test results can only be said Java in the performance of the calculation of the dynamic interpretation of the weak type of PHP, Instead of on the web. Comparing the performance of HHVM and PHP7 with the JIT mechanism can also explain this problem, in bench.php this computational script of the stress test, HHVM is 1 to twice times faster than PHP7, but in the real Web applications such as WordPress test, HHVM and PHP7 both have similar performance.

PHP is much more robust than Java, such as PHP-FPM is a classic multi-process prefork mode, the master process maintains a specified number of worker processes, and you can set how many requests the worker process will restart automatically. Anti-Java multithreaded Tomcat, in addition to memory bloat, The code is a little careless, it is possible to let Tomcat crash exit, throw a lot of error messages.

After PHP turns on Zendopcache, the script-generated opcode can be cached to the memory to form Opcache for the next request to execute directly on the ZENDVM, which can bring some performance gains.

The PHP process (Php-fpm,apache) can establish a persistent connection with Mysql/memcached/redis, a PHP process that maintains a MySQL persistent connection, Eliminates the cost of establishing a connection for each request. But notice that the number of PHP processes does not exceed the maximum number of MySQL connections, PHP-FPM will automatically reconnect when the code Mysqli_connect, but will return "MySQL server has gone Away "warning information, you can suppress the error output with @.

PHP's thermal deployment features greatly facilitate development and operation, which is not comparable to other languages such as Java (including ror/python/node.js).

I'm phper, and I've taught myself about Java WEB, and I think Java is complicated, and PHP is simple to implement. I do not comment on Java and php who is good, both are good language, but PHP on the web has a lot of advantages.

    1. PHP does not need to compile, easy to debug
      This is a huge advantage of dynamic language, there are so many changes to the Web project that compiling can waste a lot of time, which makes it difficult for Java to iterate quickly. And now the Internet is developing very fast, the demand of the fast iteration is necessary.

    2. PHP has a rich and mature framework
      YII, CAKEPHP, Zend framework, thinkphp, CI are all easy-to-use and well-honed frameworks. Java's web framework is very mature, but it's really easy to use very little. This gives a lot of web beginners a lot of barriers, so that Java programmers focus on the so-called background development, but now web developers are more inclined to all-around, Phper also because PHP is very simple, they often have the energy to learn and deepen the CSS, JS and even Linux technology. So the phper of the senior point can do nothing but paint.

    3. PHP off-the-shelf open source products
      PHP only focuses on the web, and PHP's products are web products. and PHP is easy to use, so it's easier to communicate. Like the mainstream blog system workpress, a lot of bloggers who do personality blog in order to expand their blog will also learn a little PHP. I am based on the development of Drupal, the open-source community of PHP also have some knowledge, in most cases, the PHP open source project has been able to meet most of the requirements, the wheel has someone else to do, just learn to use these open source is enough for you in the web domain to foothold. You even have more time to get into the girls ' sister.

    4. PHP is easy to deploy
      PHP is easy to deploy, whether it's Linux, Mac or Windows, or even lamp can be used by default under Linux, which is hard to transcend in other languages. It's important for beginners to be easy to deploy, and every beginner wants to be able to quickly implement their Hello world, which adds confidence to the learning process. Java beginners always have a lot of bad feelings.

As for the main topic of Java, it is true that the university education is also more inclined to java,php rarely in the university classes, so Java is more than PHP is not surprising. But in the web domain PHP is really a good solution, the enterprise implementation of Web projects in Java I think there are two reasons: First, Java is more attractive than PHP, and the second is that they already have a Java mature web solution, there is no reason to refactor the use of PHP solutions.

I have been doing Java, learning PHP The first day, the tutorial taught me to write an access counter, the result is to write the number of visits to the file inside ... Is this necessary? Do not put memory ... I went to find, just did not find, iers these two ways of thinking is completely different ...

In web development, it is generally required to fast, fast online, fast iteration. Then slowly moving towards a stable state to develop, speaking fast, have to admit that PHP to develop can save a lot of time, this is just start some startups or some start-up projects to choose PHP A large part of the reason.
You might want to ask what are the pros and cons of PHP and Java in web development, but that's not what I'm going to answer, but it's a very important factor in deciding how to develop a language.
The choice of language before development often ignores a very important issue. Sometimes it is difficult for us to consider some objective factors as a programmer, which requires an experienced technical manager to decide. In deciding which language to use for a project, it is important to consider how familiar the team members are with the language, the city you are in, and the business itself.
If your team were all a bunch of Java Daniel, would you ask them to use PHP for development?
If your team members are familiar with Java and PHP, then you need to consider the post-talent supplement. You are in a city of what kind of environment, to investigate the talent market in which language users are relatively more. (Imagine developing a new language in a small city like go, which doesn't look like a person.) )
This year's latest survey shows: in these cities in the north of the city, Java is more than the number of jobs, and PHP is more than a few people.
Wait,:-).

In general, the Java language itself is more prescriptive than PHP, and Java has a "container" concept, PHP does not exist.
But normative merit means that it is more rigid than PHP,
From a development perspective alone, Java development each feature may go entity->dao->service->action this process
PHP is a dynamic language, the most lazy when a model class and a DAO class can be compatible with all data table mappings do not need to repeat to write
So it's not a level of development efficiency.
There are some special new languages in the dynamic language, which are not the same as those of Java in rapid development.

First of all, I am a supporter of dynamic language, of course, what language in the project is mainly to see the eldest brother familiar with which, stepped on the pit which many, can quickly solve the problem.

Difference

Difference, a static language, a dynamic language, the difference is that dynamic language production efficiency is higher than static language, static language can be in the compilation period to avoid some low-level errors.

An example of high production efficiency,
Dynamic language by reflection and other black magic, you can quickly implement some static language can only rely on the compiler level of the underlying modification to achieve the characteristics (such as AOP, IOC, DI), a dynamic language developer can quickly realize the new feature is what it is to do it, without the need to make the underlying changes, So there are so many dynamic language frameworks and new features, and Ruby on Rails is an example.

Static language compilation period type check,
In fact, this feature, the dynamic language and no attraction, in the IDE and other tools to support, as well as the popularity of TDD development mode, compile-time type check is very chicken.

Why a lot of Java

The reality is that PHP is more than Java, and development and deployment are much faster than Java

On a personal point of view, Java code is better maintained than PHP.

The difference of compiler language in interpretive language

With go, no matter the development efficiency or efficiency is better than Java, and like PHP as studious, even if there is a hole, not out of the language itself

Anyway, large web sites are in Java, more value for their performance and maintainability.

In fact, the problem is very simple, and do not need too much data comparison ah what, just want to go to the recruitment site search to know, such as pull hook network, in fact, both of these technologies have a very wide application degree.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.