search
HomeBackend DevelopmentPHP TutorialPython 是否是下一个 PHP?为什么?

前几天和一个看好 Python 的 Rails 开发者聊天,他看好 Python 的原因就是 PHP 统治今天的网络应用开发。而 Python 很像下一个 PHP 。

回复内容:

python能,为什么node.js不能,为什么go不能 『下一个 PHP』如何定义?是指流行程度么?如果是的话,我觉得 Python 不会像 PHP 那样流行。根本原因在与部署难易程度。

PHP 从语言层面上讲几乎是一无是处,具体实现的质量也乏善可陈,但它胜在最要命的部署上:没有任何其他语言有像 PHP 一样适合大规模部署的方式。基本上装好 Apache/mod_php 之后,PHP 应用的部署就简化为了复制文件。即便是考虑到性能原因等采用 nginx/FastCGI 等替代方式,额外的工作也只是在于最初配置。一旦配置完成,之后的部署都是文件复制。服务器重启后通常会自动启动 apache/nginx,fastcgi manager 负责启动 php-cgi 进程等,而 PHP 应用基于文件的调用方式并不需要操心更多的维护。这对于如 Dreamhost 之类的平台来说至关重要:他们通常要一台服务器处理成千上万的低流量用户,而且这些用户没有 root 权限去运行其他进程。PHP 脚本的生命周期很短,没有常驻进程,每次调用之后就被终止,对于应用作者的要求更低,不用太多的考虑资源管理问题。

这和 Python 之流的部署有天壤之别:大部分 Python 的网络应用如 Django, Tornado 等都需要单独的常驻进程(Apache/mod_python 似乎是个杯具)。这些进程需要额外的维护工作以管理其启动、停止,也需要额外的监控进程处理意外退出后的重启。这需要用户对系统有更深入的了解。常驻进程需要占用系统内存,通常不可能在一台服务器上运行成百上千个应用,对于 Dreamhost 这样的服务提供商来说不适合用来处理诸如 WordPress 博客之类的简单应用。常驻进程也要求作者对系统资源的管理、垃圾回收机制等有更深入的了解以避免内存泄露、资源占用过度等问题。现在 Python 网络应用部署最简单的应该是 App Engine,采用了类似 PHP 的生命周期(请求处理 30 秒限制,超时被终止,无法运行常驻进程),极大简化了管理难度,但是国内无法访问…

所以从流行程度上讲,Python 不会超过 PHP,因为数量庞大的服务提供商无法用 Python 支撑现有的用户规模。但是这个流行程度对于创业公司、专业人士来说没有什么意义。很多核心的网络应用不适合用 PHP 的短暂请求处理机制实现(比如准实时 push 提醒、网页即时聊天等),而更加适合由常驻进程来处理。这些才是 Python,Ruby 等语言实现发挥其能量的地方。 Python就是Python,为什么要是下一个PHP? Python部署成问题?Python的Web应用只在虚拟主机里部署成问题,其它平台都好好的。

现在啥都缺,就不缺主机,谁还用廉价的虚拟主机? 我并不认为python可以代替php,至少目前来说还完全不可能。
原因如下:php仍然在与时俱进,同时phper和php相关程序的数量和质量仍在不断地扩大和提高。重要的一点既是,php仍然在不断维护和更新,语言各个方面在不断地提高和改善,在这个时代,被淘汰的,一直都是不与时俱进和反人类的产物 Python能干很多事情,比如数学计算、2D/3D图形处理,最近几年有很多有想法的人把Python用到科学研究、数学计算上,建立了很多科学工具、数学库,期望Python有朝一日能够像Matlab、Octave、SAGE、SciLab那样变成强大丰富的计算环境。而在Blender、GIMP等软件的背后,Python图形处理脚本已经在发挥越来越大的作用。如果你看过Blender基金会制作的三部开源动画影片,你甚至还能预期不远的未来,Python终将有一天能够进军好莱坞,成为数字电影制作的一种工具。 不同语言有不同的优势,各自擅长的领域也不同,就正如PHP对开发长时间机制的程序支持的就不是那么好,可以说就是不擅长,但是对WEB开发,快速敏捷的特别在PHP身上又体现得淋漓尽致。然而Python可以说更加强大,不单单可以做WEB开发,还可以支持开发后台数据监控,网页抓取等等长耗时应用,以及数据分析,数学计算等等高端应用。可以说各自有各自的优势,开发当中选择合适的语言就可以了,讨论谁替代谁,一点意义都没有。 apache不死,php不倒,就这么简单。 python的强大之处在于语言的简洁与优雅, 以及它强大的表达能力. hacker们愿意使用python来作为他们表达思维的方式.
在web开发上面, 正如上面Rio所言, python部署成问题, 但是对于商业网站而言, 自己处理一台vps不成问题. 而python的通用性, 能保证完成各种非常规的应用.
简单地说, 如果你只是需要web1.0的内容展示网站, 考虑php, web2.0, 可以考虑python, 以及RoR. 就python这个版本迭代速度和向前兼容性,怎么可能。。。
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How can you prevent session fixation attacks?How can you prevent session fixation attacks?Apr 28, 2025 am 12:25 AM

Effective methods to prevent session fixed attacks include: 1. Regenerate the session ID after the user logs in; 2. Use a secure session ID generation algorithm; 3. Implement the session timeout mechanism; 4. Encrypt session data using HTTPS. These measures can ensure that the application is indestructible when facing session fixed attacks.

How do you implement sessionless authentication?How do you implement sessionless authentication?Apr 28, 2025 am 12:24 AM

Implementing session-free authentication can be achieved by using JSONWebTokens (JWT), a token-based authentication system where all necessary information is stored in the token without server-side session storage. 1) Use JWT to generate and verify tokens, 2) Ensure that HTTPS is used to prevent tokens from being intercepted, 3) Securely store tokens on the client side, 4) Verify tokens on the server side to prevent tampering, 5) Implement token revocation mechanisms, such as using short-term access tokens and long-term refresh tokens.

What are some common security risks associated with PHP sessions?What are some common security risks associated with PHP sessions?Apr 28, 2025 am 12:24 AM

The security risks of PHP sessions mainly include session hijacking, session fixation, session prediction and session poisoning. 1. Session hijacking can be prevented by using HTTPS and protecting cookies. 2. Session fixation can be avoided by regenerating the session ID before the user logs in. 3. Session prediction needs to ensure the randomness and unpredictability of session IDs. 4. Session poisoning can be prevented by verifying and filtering session data.

How do you destroy a PHP session?How do you destroy a PHP session?Apr 28, 2025 am 12:16 AM

To destroy a PHP session, you need to start the session first, then clear the data and destroy the session file. 1. Use session_start() to start the session. 2. Use session_unset() to clear the session data. 3. Finally, use session_destroy() to destroy the session file to ensure data security and resource release.

How can you change the default session save path in PHP?How can you change the default session save path in PHP?Apr 28, 2025 am 12:12 AM

How to change the default session saving path of PHP? It can be achieved through the following steps: use session_save_path('/var/www/sessions');session_start(); in PHP scripts to set the session saving path. Set session.save_path="/var/www/sessions" in the php.ini file to change the session saving path globally. Use Memcached or Redis to store session data, such as ini_set('session.save_handler','memcached'); ini_set(

How do you modify data stored in a PHP session?How do you modify data stored in a PHP session?Apr 27, 2025 am 12:23 AM

TomodifydatainaPHPsession,startthesessionwithsession_start(),thenuse$_SESSIONtoset,modify,orremovevariables.1)Startthesession.2)Setormodifysessionvariablesusing$_SESSION.3)Removevariableswithunset().4)Clearallvariableswithsession_unset().5)Destroythe

Give an example of storing an array in a PHP session.Give an example of storing an array in a PHP session.Apr 27, 2025 am 12:20 AM

Arrays can be stored in PHP sessions. 1. Start the session and use session_start(). 2. Create an array and store it in $_SESSION. 3. Retrieve the array through $_SESSION. 4. Optimize session data to improve performance.

How does garbage collection work for PHP sessions?How does garbage collection work for PHP sessions?Apr 27, 2025 am 12:19 AM

PHP session garbage collection is triggered through a probability mechanism to clean up expired session data. 1) Set the trigger probability and session life cycle in the configuration file; 2) You can use cron tasks to optimize high-load applications; 3) You need to balance the garbage collection frequency and performance to avoid data loss.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Atom editor mac version download

Atom editor mac version download

The most popular open source editor