The biggest difference between java and php in web development is why java is used more.

Source: Internet
Author: User
Tags hhvm
The biggest difference between java and php for web development is why java and php for web development is the biggest difference.

Reply content:

The biggest difference between java and php in web development is why java is used more.

I feel that there are more web development backgrounds using PHP, and segmentfault should be the php background. Java provides better web Background performance and supports more requests per second, but java has a long development cycle, slow iteration, but for Small and Medium-sized websites, performance is never the key. When PV does not reach tens of millions or hundreds of millions, how to quickly iterate products by a small team is the most critical. In addition, the performance bottleneck of web backend is often in DB. Twitter was developed in Ruby before, and later changed to Java because the daily data is too big (in fact, it should be Java + Scala + Clojure ). For most Internet companies, the ability to quickly iterate products is the core of enterprise survival, and most are the background of mixed languages, not simply PHP or Java.
Technically speaking, LAMP (Linux + Apache + MySql + PHP) is basically the standard on the Internet, and framwork based on PHP is obviously more.
Companies using PHP: N many small and medium-sized sites, such as Baidu, QQ, and facebook. Of course, these companies also use Java
Java: ebay, Alibaba, Twitter

Is PHP's Web Application Performance worse than Java? Take querying MySQL to obtain the result set and display data on the page as an example for analysis. HTTP requests are processed by C-level programs such as Apache/Nginx (Java HTTP services use Tomcat developed by Java ), PHP calls the database driver mysqlnd developed in C built in the PHP engine (Java uses the JDBC driver developed in Java) to operate MySQL, the focus of the query logic is on MySQL developed by C/C ++. Then, the returned result set is placed in the PHP array and output on the page after string processing, these logics are not complex, and PHP load is not large. it is worth noting that a large number of built-in PHP library functions are all implemented in C, while the core runtime class library rt of Java. jar is implemented in Java.

In some stress tests under CLI, due to a large number of loops, it is easy to trigger Java JIT hotspot compilation. At this time, Java's computing performance has increased to the level of C, such test results only mean that Java's computation performance is limited to dynamic interpreted weak PHP, rather than on the Web. comparing the performance of HHVM and PHP7 with JIT mechanism, this problem can also be explained in kernel. in the stress test of the php computing script, HHVM is one to two times faster than PHP7, but in the test of Real Web applications such as WordPress, the performance of HHVM and PHP7 is similar.

PHP running mode is much more robust and stable than Java, for example, PHP-FPM is the classic multi-process prefork mode, the main process will maintain a specified number of worker processes, you can set the number of requests processed by a worker to be automatically restarted. in contrast, in addition to memory expansion, the Java multi-thread Tomcat code may crash and exit, throwing a lot of error messages.

After ZendOpcache is enabled for PHP, You Can cache the opcode generated by the script to the memory to form opcache For The Next request to be executed directly on ZendVM, which can improve the performance.

The PHP process (PHP-FPM, Apache) can establish a persistent connection with MySQL/Memcached/Redis, a PHP process maintains a persistent connection to MySQL, saving every request to establish a connection overhead. but note that the number of PHP processes should not exceed the maximum number of connections in MySQL, timeout or restart MySQL after the PHP-FPM will automatically reconnect in the Code mysqli_connect, however, the "MySQL server has gone away" Warning information is returned. You can use @ to suppress error output.

The hot deployment feature of PHP greatly facilitates development and O & M, which is incomparable to other languages such as Java (including RoR, Python, and Node. JS.

I am PHPer and I have learned java web by myself. I think JAVA is very complicated, but PHP is very easy to implement. I don't comment on JAVA and PHP, both of which are good languages, but PHP does have many advantages on the WEB.

  1. PHP does not need to be compiled and is easy to debug
    This is a huge advantage of dynamic languages. There are too many changes to WEB projects and compilation will waste a lot of time, making JAVA difficult to quickly iterate. Now the Internet is developing very fast, and the demand for rapid iteration is necessary.

  2. PHP has a rich and mature framework
    YII, CAKEPHP, Zend Framework, ThinkPHP, CI and so on are easy to use and time-tested frameworks. Java web frameworks are mature, but few are actually easy to use. This gives a lot of WEB beginners a threshold and allows JAVA programmers to focus more on the so-called background development. However, WEB developers are more inclined to be full-featured, and PHPer is also very simple because PHP, they often have the energy to learn and deepen CSS, JS, and even LINUX technologies. Therefore, PHPer of senior users may be able to do anything but not do painting.

  3. PHP has many ready-made open-source products
    PHP only focuses on the WEB field. PHP products are WEB products. PHP is easy to use, so it facilitates easy communication. Like the mainstream BLOG system workpress, many bloggers who make personalized blogs will learn a little bit about PHP in order to expand their blogs. I developed it based on drupal and have some knowledge about the open-source PHP community. In most cases, PHP open-source projects can already meet the vast majority of requirements, and others are doing well, just learning to use these open sources is enough for you to gain a foothold in the WEB field. You even have more time to get a girl.

  4. PHP is very easy to deploy
    PHP is easy to deploy in LINUX, MAC, and WINDOWS. By default, LAMP can be used directly in LINUX, which is hard to surpass in other languages. Ease of deployment is very important for beginners. Every beginner wants to quickly implement their own Hello World, which will increase confidence in the future learning process. JAVA Beginners always have a lot of self-defeating feelings.

As for the subject, it is true that there are many JAVA applications. university education is also more inclined to JAVA, and PHP rarely starts classes in the university, so it is not surprising that JAVA is more popular than PHP. However, PHP is indeed a good solution in the WEB field. I think there are two possible reasons for enterprises to implement WEB projects using JAVA: first, JAVA is better than PHP, second, they already have a mature java web solution, so there is no reason to refactor the PHP Solution.

I have been working on Java. I learned PHP for the first day. In this tutorial, I was taught to write an access counter. In this case, I had to write the number of accesses to the file... Is this necessary... Can't I put it in memory... I did not find it. The two ways of thinking are completely different...

Web development usually requires fast, fast online, and fast iteration. Then we gradually develop into a stable State. Speaking of speed, we have to admit that using PHP for development can save a lot of time, this is also a big part of the reason why some startups or some startup projects choose PHP.
You may want to ask what are the advantages and disadvantages of PHP and JAVA in Web development. I will not answer these questions, but it is an important factor that determines the development language.
Language selection before development often ignores a very important issue. Sometimes it is difficult for us to consider some objective factors as a programmer, which needs to be determined by experienced technical managers. When determining the language used for development of a project, you must consider the degree of familiarity of the team members with the language, your city, and your own business.
If your team is a group of JAVA experts, will you ask them to use PHP for development?
If your team members are familiar with JAVA and PHP, you should consider adding talents later. What is the environment of your city? You need to check which language in this talent market has a relatively large number of users. (Imagine using a newer language for development like Go in a small city. That would not be easy .)
According to the latest survey this year, JAVA has many jobs in Beijing, Shanghai, Guangzhou, and Shenzhen, while PHP has many jobs.
Wait :-)

In general, the java language is more normative than PHP, and java also has a "Container" concept, while php does not exist.
However, normative optimization means it is more rigid than PHP,
From the development perspective alone, java may develop each function using the entity-> dao-> service-> action process.
Php is a dynamic language. When you are lazy, a Model class and a Dao class can be compatible with the ing of all data tables and do not need to be written repeatedly.
Therefore, the development efficiency is not a level.
Some new dynamic languages cannot be considered by java compilation languages in terms of rapid development.

First of all, I am a supporter of Dynamic Language. Of course, the main language used in the project depends on which of the elders are familiar with and which has many pitfalls and can solve the problem quickly.

Differences

Difference: a static language, a dynamic language, the difference is that the production efficiency of dynamic languages is higher than that of static languages. Static languages can avoid some low-level errors during compilation.

Examples of high production efficiency,
Dynamic Language uses black magic such as reflection to quickly implement features (such as AOP, IOC, and DI) that can only be implemented by underlying compiler-level modifications ), A Dynamic Language developer can quickly implement the new feature without having to make the underlying modifications. Therefore, there are many dynamic language frameworks and new features emerge in an endless stream, ruby on Rails is an example.

Static language type check during compilation,
In fact, this feature is not very attractive to dynamic languages. With the support of IDE and other tools, and the popularity of TDD development methods, the type check during compilation is very bad.

Why java

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

In my opinion, Java code is better maintained than PHP.

Differences between interpreted and compiled languages

With go, both development efficiency and running efficiency are better than JAVA, and they are as studious as php.

Anyway, large websites use Java and focus more on their performance and maintainability.

In fact, this problem is very simple, and there is no need to compare too much data or anything. You just need to search for it on the recruitment website, for example, net, in fact, both technologies have a wide range of applications.

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.