What can be done in Python, but not in PHP?

Source: Internet
Author: User
Tags php multithreading what php
What can be done in Python, but not in PHP? What can be done in Python, but not in PHP? Reply content:

The python programmer named "Ling Jian" said nonsense, not only in the answer, but also in the comments with his expired junior PHP qualifications, and also came out to give it a few bits.

First of all, as mentioned below, have you heard of "Turing complete? If you have never heard of it, you can go to Wikipedia first (https://zh.wikipedia.org/wiki/%E5%9C%96%E9%9D%88%E5% AE %8C%E5%82%99%E6%80%A7. Php and python are completely Turing languages, so there is nothing one can do but the other cannot do.

The answer is complete. The following is the time for face preparation, that is to say, let's take a look at what the so-called python can do and what php cannot do (to avoid repetition, I will not repeat the "groove" part that has been refuted, and some wonderful comments are extracted from his comment on "Lingjian ):
1. "I used to write PHP with curl, which is a C library. It doesn't mean it is not good, but if you use this library, there are some important functions that won't work. for example, I want to read a URL and then process the returned value as a stream, read Part of processing ": Please read the manual PHP: curl_setoptCURLOPT_FILE, "value shocould be a stream resource (using fopen (), For example) for the following values of the option parameter "indicates that the stream is supported.
In addition, it is said that you have gone through a lot of third-party libraries? Unknown guzzle (GitHub-guzzle/guzzle: Guzzle, an extensible php http client) Do you know if you have read this 7000 + star Library?
2. "It is better that the returned stream can be processed in the same way as a file. you can simply write the stream to other languages using methods such as outputStream, but PHP doesn't work, as mentioned above, you are all fopen. of course, you can process them in the same way as files.
3. "other things, such as automatically reusing HTTP/1.1 Connections, cannot be done." You are talking about web server. Go to apache/nginx. Of course, you have to use php as a web server. swoole is one, but you don't think this is an extension of c writing. Then you can check out workerman (what? This also uses the c library, so not counting? Please, it's too much for you not to use the library that comes with the system ).
4. "The O & M team complained that the front-end nginx configurations of Web services in other languages are uniform, only PHP, and a lot of rewrites are written. Because PHP does not support binding handler by URL matching rules ": Who is the blame for your bad business rewrite? Most of the mainstream frameworks are now designed with a single portal. all of them are rewritten to index. php and then distributed and processed internally.
5. "You always think that PHP can do the same thing. I think this is because the business you want to implement is too simple and you have never seen a really beautiful design .』 : Similarly, you have too little knowledge and skills, and php can also implement what you call exquisite design.
6. "Only your PHP is poorly designed. because the syntax is too dead, you can only write the noodle code, read other languages such as Python and Java (Java is much better than you) and see how they use OOP to abstract business logic and how they use design patterns, how to use a modular approach to manage business functions, and how to provide plug-in-type extensions, none of your PHP can do. 』 : PHP: IntroductionPhp5 (more than 10 years ago) has provided OOP. isn't it a program to abstract business logic, use design patterns, and modularize plug-ins? What is your poor language?
7. "I have written PHP for at least three years on SAE (Sina Cloud service). during the peak application period, I ran SAE (that is, I ran fsockopen ), I have encountered all of the most disgusting PHP problems. 』 Why is it SAE spam php? How many times have I crashed? can I blame PHP for having changed so many things in the back of SAE? At that time, I recommended SAE and xinlang cloud store to the boss (it seems to be called this name, that is, SAE with no write restrictions). as a result, all kinds of pitfalls were deployed.
8. "only your PHP family needs to be differentiated. third-party extensions can only be copied to the website directory. there is no package management function, and you need to be careful about namespace conflicts. is it great? C. How nice is it to change the configuration file when it is difficult to scale up and install it ?』 : For php package management, see ComposerNamespace conflicts are also solved by the way. For C extension, see pecl
9. "But do you really want a language that searches for local directories every time with a class?": Please read the psr-0, psr-4, and composer autoload.
10 "the automatic loading mechanism depends on the local directory to find the file that matches the class name and then load it.": You can also implement PHP: spl_autoload by yourself without following the rules.Then, how do you feel better.
11. "namespace conflict": PHP: Using namespaces: Aliasing/Importing
12. "One major support for Java Web is spring. because spring is available, it can be used to build a large-scale, plug-in-type Web that can use the design pattern. PHP cannot work. this is already the death penalty, it means PHP will never develop Web applications of the Java scale. 』 : I guess what you want to talk about is IOC? Many of these frameworks have also been implemented, such as Service Container.,
By the way, how small is facebook in your eyes?



There are too many slots, so I 'd like to explain some basic things:
First, php is written in C. Is there any problem? According to your logic, only the user who can perform self-lifting can be called a language?
As for loading every time, this is determined by working with apache/nginx. Translate your questions a little professionally. can php implement web server by itself? The answer is yes. First, php-S comes with one. you can also refer to the project swoole (c implementation) and workerman (php implementation ).


Finally, it's hard for you to be proficient in php. Does it hurt so many faces? Many people discuss python and php in terms of language. My capabilities are limited. I can only discuss it from the resource ecosystem.

Refer to two awesome.

Ziadoz/awesome-php

Vinta/awesome-python

We can hardly find that php is mainly developed for web development. Python involves many fields, except the web:

  • Big data processing

  • Data Visualization

  • Machine learning

  • Embedded Development

  • APIs of major software

  • Desktop applications


Thanks to the relationship between CPython and C, many software have developed python api interfaces. In terms of efficiency, numpy and pandas are essential for processing data using python. Of course, it is understandable to use php to quickly create a webapp. after all, it is the best language.

Python Note 1: Getting started and commentsZhihu is about to form a situation where he is proud to write python and he is ashamed to write php. Is it really frustrating to write php? Python black php is about to become politically correct.
Now, python cannot be used in php. although we all use Turing, can php be used as a language?
Python can be used to install B, so php cannot. In Zhihu, phper is usually suspended by pythoner.
Python versions 2 and 3 are available for you at any time, so php cannot.
Python can also do this: a = [1, 2, 3] calculates the length len (a), sorts,. sort () is simply a process that absorbs both the C Series and the object-oriented model. it is very touching, and php will not work. they are all ugly process calls.
The indentation of python is the gospel of code cleanliness, and there is no ugly code door.

The above is just a bit of nonsense. I only know php and ruby, but I really feel that python is still a good language, and List comprehension similar to Haskell. I can't help it. the python codenon of the Lingjian can't help it. I was wondering why you answered the question in the dark php. Black php is okay and I am always black, but your answer to php is simply not knowledgeable and you are still confused. here, I will give you a comment on your answer.

1. "Special differences in multithreading support are only one of them ." To put it this way, php, ruby, python, and other mainstream scripting languages, such as multithreading support, are the best. Py and ruby support multi-thread cutting-corners and global locks to create fake multithreading. php itself transformed the language core into a thread-safe and non-thread-safe version, and php multithreading is a real multi-thread. In fact, as a high-level language, multithreading is not robust, so I basically don't need multithreading. I prefer to use java/c ++ static language to use multithreading tasks.
2. "for example, if you do not distinguish between byte streams, multi-byte strings, and unicode strings, you must use hexadecimal escape for all unicode, UTF-8, and gbk strings in the PHP file, what is a crashing experience ". Which of the following are disgusting times when python is not coded? I have never worried about coding in php. Do you mean Mao doesn't need py3? Yes, py3's silly incompatibility with py2 has brought a lot of trouble to the third-party library community. ubuntu16.04 dared to upgrade py3. I'm sorry for the centos6 and py2.7 in most production environments.
3. "for example, if multiple values are returned, Python can return tuples and then use a simple syntax (a, B = my_func () to restore the contents of the tuples to different variables. PHP can only return arrays, then write several lines of ugly code." Php can not only return arrays, but also objects. However, I believe that php does not have the syntax sugar like py. I am not very concerned about the syntactic sugar. I also checked it when I used it. the features you mentioned in php seem to include: $ my_array = array ("Dog", "Cat ", "Horse"); list ($ a, $ B, $ c) = $ my_array; but this is not important at all.
4. "PHP can continue to do so until today, because it is the first module that can call C, so it relies on C programmers to continue step by step. this is also true for swoole; "php writes cpu-intensive functions into the c module for performance. what is black? Php7 best features are also in the best compatibility with the premise to improve performance: https://pages.zend.com/rs/zendtechnologies/images/PHP7-Performance%20Infographic.pdf. As far as my judgment is concerned, the php language and community have developed very well.
5. "The second reason is that PHP programmers generally have a low quality and the demand for code writing is narrow, so they have never met the hard boundary of this language. Basically, if you write Python once or twice, you won't try to use PHP again ." It is wrong for you to use map guns like this. Every language has its own use scenario. I originally wrote a lot of py files, but I think php is more useful for web applications.
6. "When did someone use PHP to write a cloud computing management platform such as OpenStack, a compact and exquisite Web framework such as Flask, and a simple and easy-to-use crawler framework such as Scrapy, even HTTP clients such as requests are still using libcurl. let's talk about what PHP cannot do." OpenStack has never been difficult to evaluate. Flask has been used in this group for reconstruction and conversion to java since it encountered performance problems. Scapy and requests are coming soon. I will use this 2 to face you today. As a crawler framework, Scrapy can basically write several configuration files, but the essence of crawlers is to enable an httpclient to retrieve html + dom operations to extract data, scrapy package is very suitable for beginners to modify a few parameters to run, but the expansion is particularly poor. In this case, all the crawlers that require special customization are directly launching requests back to beautifulsoup to extract data. The httpclient of requests is quite useful, and the httpclient of php is not only libcurl. for a large library, guzzle is also very useful and has great asynchronous support. With guzzle, I can use the libevent event Library. a single process can only open one httpclient of guzzle and simultaneously asynchronously crawl 100 websites. requests does not support asynchronous access.

If I say so much, I just want to face you.



-------------------------------------------------
After reading the Coldwings response, I was very interested. the response here is as follows:

1. I believe it is clear enough to discuss the encoding issue. I think what you said makes sense. here, we will not respond to emotional things.
2. I have investigated the asynchronous concurrency scheme in py for a long time. grequests (GitHub-kenthreitz/grequests: Requests + Gevent = <3) is a thin packaging of gevent, there are a lot of star codes but less than 150 lines of code, which is actually not very useful.
3. coroutine essentially writes data asynchronously in synchronous mode. Therefore, coroutine does not mean that it is more concurrent than asynchronous.
4. not only Scrapy can schedule phantomjs (you can integrate phantomjs into any crawler ), in fact, I have some experience in php concurrent driver phantomjs (single-host i7 concurrent driver 80 phantomjs instances, including concurrent caching, proxy, resource leakage, and difficulties in headless development), I believe that using py to drive phantomjs is similar, depending on what you use.
5. crawler the so-called distributed crawling refers to multi-host concurrent crawling. I use a lot of redis, of course, I don't have many machines. I used php to write a multi-node concurrent crawler solution based on redis. I have a crawler with 2 PCs and a maximum of 150 httpclient phantomjs + 150 guzzle. Redis is recommended for multi-crawler collaboration and task distribution compared to dedicated message queues, because redis's single-host qps of 10 million meets the concurrent crawler, there are also 5 useful data structures, which are helpful for crawler scheduling, status viewing, and parameter dynamic settings.
6. my crawler concurrency is 100 because http concurrency is not tcp concurrency. I use php to run asynchronous concurrency in a single process, single httpclient, low cpu, and low memory, full of small pipe. I think the advantages and disadvantages of the thread pool solution and asynchronous concurrency solution have been discussed clearly enough (in addition, I really think my single httpclient asynchronous multi-concurrency crawler solution based on guzzle is very good, I am complacent about this. If you are interested, you can refer to my two blogs to discuss this question: Talking about crawler concurrency.Experience with redis + high-concurrency httpclient).
7. I have also investigated the concurrent http scheme of python before (What is the fastest way to send 100,000 HTTP requests in Python?), Which includes the asynchronous httpclient of grequests and tornado. The asynchronous httpclient of tornado is based on libcurl (tornado. httpclientBut php guzzle is libcurl by default, but you can choose other event libraries such as libevent, guzzle supports asynchronous concurrency (I haven't found such httpclient in py and java for a while ).

Finally, I just saw that the python code Nong Hei php of Lingjian was really wrong in every sentence (from his previous answers, he also saw that the prejudice against php was too great, in addition, he doesn't know php at all, which leads people to get angry.) he just jumps out and makes a face. I believe that each language has its most suitable scenario, and it also enjoys communicating with others about some technical things. Thank you. I do not know it on the web. the multi-threaded php mentioned above can be completed using swoole.
The best part of php's design is to extend this mechanism. even if py has other new features on the web, php can also use C to provide an extension for php.
In short, each language has its own meaning. do not compare it with each other. if you have such a relative time, it is better to write a few more pieces of code. Python can write code without the dollar sign.
PHP cannot. Thank you! The two languages face different fields. if we force horizontal comparison, it will inevitably lead to meaningless disputes.
Before the birth of the PHP language, the WEB is already a red ocean. according to the above python, PHP is not necessary at all. However, PHP has emerged and continues to grow. it has occupied most of the web development market.
The emergence of everything has its inevitability. in the future, the Internet technology field will become more and more inclined to implement quickly. Believe that if it is not Dz! In the past few years, BBS will not develop so rapidly in China. It can be seen that PHP has made great contributions to the development of the Internet in China and the world.
Many people are saying that Zuckerberg regretted using PHP, but if he didn't choose PHP at the time, he might not be able to dominate FB. Bill Gates was not perfect when he launched the Windows operating system. to cultivate user habits early, he would rather push the software he thought was not perfect into the market. If he wants to pursue perfection and then launch it again, even if it is perfect at that time, there will not be so many people using it.
This fleeting business opportunity makes PHP brilliant. First launch available applications and then spend time improving them. Even using C will also get a lot of support, because the market has applied for the feasibility of the application.
Therefore, PHP and PY cannot be compared horizontally. what is PY that cannot be done in PHP, my answer is that projects with sufficient time and feasibility are not suitable for PHP, such as customized ERP. Something Php can't do. curious! In fact, only py can do php.

The personal taste of the selected language accounts for a certain proportion. If the person selected at that time had done some influential work, it would have formed inertia, and then it would have been hard to stop.

A large part of py is used for numerical computation, and there are many databases. Some people have previously listed some reasons: why those who are engaged in numerical computation prefer python rather than other languages, one of which is more syntactically accepted by these scientists.

So if you have to say that the same py can do something that php cannot do: it may be that the py syntax is more attractive to users in other industries.

10 Reasons Python Rocks for Research (And a Few Reasons it Doesn't)

For more information, see. The problem is too subjective.
Ask the subject to define exactly what is "not allowed"
C/c ++ can be used for web development, bash can also write scientific computing, and even node. js can be extended to embedded development.
There is only a relative, qualitative "unsuitable" and no "not allowed"

What can be done in Python, but cannot be done in PHP? For more information, see The PHP Chinese website (www.php1.cn )!

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.