What is Python to do, but PHP can't do?

Source: Internet
Author: User
Tags php language php multithreading what php

What is Python to do, but PHP can't do?

Reply content:

See that the "Ling Jian" python programmer is nonsense, not only in the answer, the comment is also holding their own outdated junior PHP qualifications in that mouth, also come out to give it a few slaps.

First of all, the following has been mentioned, pro, have you ever heard of "Turing complete"? If you haven't heard anything, 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) Tutorial. PHP and Python are all Turing-complete languages, so there's nothing that accesses than either can do and another can't do.

Answer the question, the following is a good deal of the face time, that is, to see the "Spirit Sword," what the so-called Python can do and what PHP cannot do is exactly what it is (to avoid repetition, "groove" has been refuted part of the I do not repeat, some of the wonderful remarks from the "Spirit Sword" his comments):
1. "I used to write PHP mainly using curl, this is a C library. Not that it's bad, but if you use this library, there are some important features that don't work, like I'm going to read a URL, and then process the return value as a stream and read part of the process ": Read the manual php:curl_setoptCurlopt_file, "value should be a stream resource (using fopen (), for example) for the following values of the option parameter "explicitly stating that the stream is supported.
Besides, you're also said to have seen a lot of third-party libraries? Don't know Guzzle (Github-guzzle/guzzle:guzzle, an extensible PHP HTTP clientThis 7000+ star's library doesn't know if you've seen it?
2. "The best way to return the flow can also be as unified as the file processing, directly with the OutputStream and other methods can be written to other languages basically support such a function, but PHP does not" ibid, above has said, you are fopen, of course, can be like a document unified processing
3. "Other, such as the automatic reuse of http/1.1 connection, but also do not do" nonsense, you say this is the Web server thing. Find Apache/nginx to go. Of course you have to take PHP to do Web server is not no, swoole is a, but you think it is C write extension does not count. Then you can go and see Workerman (what?) This also uses the C library, so it doesn't count? Please, the system comes with the library you are not allowed to use this is too much to point it.
4. "Ops just complained, the other language Web services, the pre-nginx configuration is unified, only PHP, wrote a lot of rewrite." Just because PHP does not support binding by URL matching rules handler ": You're in a bad business. Who's a lot of rewrite? The mainstream framework is now basically a single-entry design, all rewrite to index.php and then distributed internally.
5. "You always think PHP This can also be the same, I think it is entirely because you want to achieve the business is too simple, have not seen a really beautiful design." "In the same way, your ability is too poor to see too little, PHP can also be to achieve what you call the exquisite design."
6. "Only your home PHP is beautiful design is not good, because the syntax is too dead, so you will only write the noodle code, read other languages such as Python, such as Java (Java is also much better than you), see how they use OOP to abstract business logic, how to use design patterns, How to manage business functions in a modular way, how to provide plug-in extension, these your home PHP can not do. ": php:introductionPHP5 (more than 10 years ago) began to provide OOP, as for abstract business logic, the use of design patterns, modular plug-ins are not all programs? You're a bad language, huh?
7. "I've written at least three years of PHP on the SAE (Sina Cloud Service), I've run over the SAE at the peak of my application (that's fsockopen), and I've had all of PHP's most disgusting problems." "Is that the reason it's the SAE Garbage monster PHP?" I also ran over more than a few times, SAE secretly changed so many things can blame PHP? At that time to the boss recommended SAE and Sina Cloud Store (like the name, is not the limit of the SAE), the result of the deployment of various pits AH
8. "Only your home PHP to differentiate, third-party extensions can only be copied into the Site directory, no package management functions, but also careful namespace conflicts, cool?" C expansion to install the cost of the old to change the configuration file, cool? ": PHP package Management please refer to ComposerNamespace conflicts are also resolved by the way. For C extension please refer to Pecl
9. "But do you really want a language that searches the local directory every time you use a class?": Read psr-0, psr-4 and composer AutoLoad
10 "The automatic loading mechanism is to find a file that matches the name of the class name in the local directory and then load it right": You can also do it yourself without the php:spl_autoloadThen how do you feel about it?
11. "Namespace conflict": Php:using namespaces:aliasing/importing
12. "Java Web a big support is spring, because there is spring so can build a large-scale, plug-in, can use the design model of the web,php No, this is the death penalty, that PHP will never be able to develop Java this size of Web applications." ": I guess what you're trying to say is the IOC, right?" Many of these frameworks have also been implemented, such as Service Container
By the way, don't know how small the size of Facebook is in your eyes?

There are too many slots to say, some of the most basic things I would like to explain:
First of all, PHP is written in C, what is the problem? According to your logic, only the ability to accomplish the bootstrap can be called a language?
As for each time it is loaded, this is determined in a way that works in conjunction with Apache/nginx. Translate your question a bit more professionally, can PHP implement Web server itself? The answer is yes. First php-s comes with one, you can also refer to project Swoole (c implementation), Workerman (PHP implementation), etc.

Finally, do not know PHP also to install proficient to strong black, really hard you. Is it painful for so many people to hit their faces? Many people talk about Python and PHP from a language level. My ability is limited, can only be discussed from the resource ecology.

Take a look at two awesome.



It's easy to see that PHP is primarily for web development. Python involves many areas, with the exception of the Web:

    • Big Data processing

    • Visualization of data

    • Machine learning

    • Embedded development

    • APIs for major software

    • Desktop Apps

Thanks to the relationship between CPython and C, many of the software is out of Python's API interface. As far as efficiency is concerned, using Python to do data processing is definitely inseparable from Numpy,pandas. Of course, want to quickly do a webapp with PHP is understandable, after all, it is the best language.

Python Note one: Simple introduction and reviewsKnow is about to form a to write Python proud, to write PHP is ashamed of the situation, it is very painful to write PHP is very embarrassing? Holding Python black PHP is about to become a politically correct thing to know.
Now it's all out of Python. PHP can not be such a problem, although everyone is Turing equivalent, but PHP can also calculate language?
Python can be used to install b,php, in the knowledge phper will usually be pythoner amputated
Python can have 2, 32 versions ready for you to choose, PHP will not.
Python can do this: a = [All-in-one] length Len (a), sort, a.sort (), is simply absorbing the C-system process and absorbed the object-oriented, simply touching, PHP is not, are ugly process calls.
The indentation of Python is simply the Gospel of code cleanliness, and there is no door to writing ugly code.

It's just nonsense, just a little bit of PHP, Ruby, not Python, but it really feels like Python is still a good language, and a list comprehension like Haskell. Can not help, the spirit of the Python Code of the Sword, and before the problem of black PHP to see you blind answer. Black PHP No problem I also often black, but your about PHP answer is pretend also nonsense, here to your answer a sentence to hit your face.

1, "Multithreading support special poor is just one of them. "So to speak, PHP, Ruby, Python and other mainstream scripting language in the multi-threaded support, PHP is the best." PY and Ruby support multithreading Jerry Plus global lock get a fake multi-threading, PHP itself to transform the language core of the thread-safe and non-thread-safe version, PHP multithreading is true multithreading. In fact, the scripting language as a high-level language multithreading is not robust so I basically do not have multi-threading features, to use multi-threaded tasks I still prefer to use java/c++ static type language.
2, "For example, do not distinguish between byte stream, multibyte string, Unicode string, you need to write in PHP file Unicode, Utf-8, GBK strings must all be escaped with 16, this is a kind of what a crash experience." A few of the disgusting ones with Python not coded disaster? I don't have to worry about coding problems with PHP. You say you don't py3 for fur? Yes, py3. Incompatible py2 to third-party library community to bring much trouble, ubuntu16.04 dare to Rise py3, sorry most of the production environment CENTOS6 also py2.7 it.
3, "For example, multiple return values, Python can return a tuple and then use simple syntax (A, B = My_func ()) to restore the tuple content to different variables, PHP can only return an array, and then write several lines of ugly code." "PHP can not only return an array, but also return objects and so on, but I believe you mean that PHP does not have the same syntax as PY." Grammar sugar This thing I am not very care, also used to check, you say this feature PHP seems to have: $my _array = Array ("Dog", "Cat", "Horse"); list ($a, $b, $c) = $my _array; but it doesn't matter at all.
4, "PHP can continue to live today mainly because the first can adjust the C module, so rely on C programmers step by step, Swoole is the same;" PHP is the CPU-intensive function C module is for performance Ah, what is the black? The best features of PHP7 are also to improve performance as far as compatibility is possible:https://Pages.zend.com/rs/zendtechnologies/images/php7-performance%20infographic.pdf。 As far as my judgment is concerned, PHP language and community development is very good.
5, "The second because the PHP programmer general Quality is relatively low, the requirements of writing code is very narrow, so never encountered the hard boundary of the language." Basically to write one or two times Python, you will not want to re-use back to PHP. "You are not such a map cannon, each language has the use of each language scene, I originally wrote Py quite a lot of, but web-related I think PHP is better."
6, "When someone uses pure PHP to write a cloud management platform such as OpenStack, flask such a small and sophisticated web framework, scrapy such a simple and useful crawler framework, Even HTTP clients such as requests are still dragging libcurl to make a difference today, so let's talk about what PHP can't do. "OpenStack has not been used to evaluate the inconvenience, flask This group has been in use in the face of performance problems after refactoring to Java, scapy and requests you can open your mouth today I use this 2 dozen your face. Scrapy as a reptile framework to write a few configuration files can run, but the nature of the crawler is to open a httpclient retrieve Html+dom operation extract data, Scrapy package is very good for beginners to change a few parameters to run up, but the expansion is particularly poor. This side of the crawler of the PY code farmers in order to complete the needs of special custom crawlers are directly open requests back beautifulsoup pumping data. Requests this httpclient is very useful, PHP httpclient is not only libcurl, than the larger library words guzzle is also very useful, and has a great asynchronous support. I used guzzle to use the Libevent event Library single process to open only one guzzle of httpclient concurrently and asynchronously crawl 100 sites, while requests did not support asynchronously.

I said so much just want to hit you in the face, above

Looked at the coldwings of my comparative level of answer, I am in a good mood immediately, here respond to the following:

1, about the coding problem I believe that has been discussed enough clear, I think you say there is a reason, sentimental things here will not respond.
2. Asynchronous concurrency scheme under PY I've been researching for a long time, grequests (github-kennethreitz/grequests:requests + gevent =<3) is a very thin package for gevent, Star is a lot but the code is 150 lines less, actually not very useful.
3, the co-process is essentially asynchronous synchronous way to write, so the association is not to say in concurrency than asynchronous strong.
4, not only Scrapy can dispatch PHANTOMJS (you can integrate PHANTOMJS into any crawler), in fact, I have some experience in the concurrent driving PHANTOMJS under PHP (Single-Machine i7 concurrently drive 80 PHANTOMJS instances, including the concurrent cache, Agent, resource leakage and headless development difficulties, such as the corresponding treatment of various pits, I believe with PY to drive the PHANTOMJS is also similar, see you use what handy.
5, crawler this piece of your so-called distributed refers to multi-machine concurrent crawling, I use Redis more, of course, I do not have many machines. I wrote a Redis-based multi-node crawler program myself with PHP, with a crawler of 2 PCs with a maximum of 150 phantomjs+150 guzzle httpclient. Multi-crawler collaboration and task distribution what, compared to a dedicated message queue I recommend Redis, because the Redis single-machine 10w QPS to meet the crawler concurrency at the same time, there are very useful 5 kinds of data structure, the crawler scheduling, State view, parameter dynamic settings are very helpful.
6, my crawler concurrency 100 is HTTP concurrency is not TCP concurrency, I use PHP in a single process single httpclient under low CPU low memory asynchronous concurrency ran full of small water pipes. Thread pool scenarios and asynchronous concurrency scenarios I think it's clear enough (and I really think my guzzle-based single-httpclient asynchronous multi-concurrency crawler scheme is pretty good, and I'm complacent about that. If you're interested, take a look at one of my two blogs on this topic: talking about the concurrency of reptilesand the understanding of Redis usage + high concurrency httpclient)。
7. Python's concurrent HTTP scenario I've also investigated before (what's the fastest-to-send 100,000 HTTP requests in Python?).), which also has the asynchronous httpclient of the grequests and tornado you mentioned. The asynchronous httpclient of tornado is precisely based on Libcurl (tornado.httpclientAnd there is no concurrency support, and PHP guzzle default is Libcurl but you can choose another event library such as Libevent, guzzle but support asynchronous concurrency Oh (under the PY and Java I haven't found such a httpclient for some time).

Finally, I just see the Spirit sword that Python Code black PHP really is every word is wrong (from his previous answer also see the bias on PHP too big, and he does not know PHP, so misleading others really let people fire big), really can't stand to jump out to face. I believe that every language has its most suitable scene, but also fully enjoy communicating with other people some technical things. Xie invited, on the web as far as I know is no, the above mentioned multi-threaded PHP can use Swoole to complete, nor can not do.
PHP in the design of one of the best place is to extend this mechanism, even if the py in the web after the other new features, the C-language of the PHP God can also use C out an extension to PHP.
In short, each language exists has its meaning, do not compare, if you have this comparison of time, it is better to write a few more pieces of code. Python can write code without a dollar sign.
PHP cannot. Thanks for inviting! The two languages face different fields, if the force of horizontal contrast, will inevitably lead to meaningless disputes.
Before the birth of this language in PHP, the web is already a piece of red Sea, if according to the above-mentioned Python great God, PHP is not necessary to appear. However, PHP has emerged, and is growing, has now occupied most of the web development market.
The emergence of any thing has its inevitability, the future of the Internet technology will be more and more inclined to achieve fast. Believe that if not the emergence of dz!, the previous years BBS will not develop so rapidly in the country. It can be seen that PHP has contributed greatly to the development of the Internet at home and around the world.
Many people are saying that Zuckerberg regrets to use PHP, but if he did not choose PHP at that time, there may be no FB hegemony. Bill Gates when the introduction of Windows operating system is not perfect, he in order to develop user habits early, rather than think of the software is not perfect to push into the market. If he wants to pursue perfection and then launch it, maybe that time, even if it's perfect, there won't be so many people to use it.
This is a fleeting business opportunity to create a brilliant PHP. Start with the available applications and spend time perfecting them. Even the use of C will get a lot of support, because the market has been applied to the feasibility of the application.
So PHP and PY can not be compared horizontally, as to what is the PY can do PHP cannot do, my answer is that there is ample time, ample feasibility of the project is not suitable for PHP, such as tailor-made customized ERP. There is no PHP can do, curious! In fact, there is no only py can do PHP can't do.

The choice of language personal taste accounted for a certain proportion. If the chosen person happens to be doing a lot of influential work, then the inertia is formed, and then it is too late.

PY has a large part of the application is numerical calculation, the library is also very much. There have been some reasons why those who do numerical calculations prefer Python to other languages, and one reason is that they are more likely to be accepted by these scientists.

So if you have to say the same, the PY can do PHP does not work: it may be the PY syntax is more attractive to other industry users.

Reasons Python Rocks for (and a Few reasons it doesn ' t)

Put a link to reference. The problem is too subjective.
Ask the master to define exactly what "can't be done".
C + + can do Web development, bash can write scientific calculations, and even node. JS can be extended to embedded development
There is only a relative, qualitative "not suitable", there is no "can not do"

So that's what Python can do, but what PHP can't do? For more information, please pay attention to topic.alibabacloud.com (www.php.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.