php PHP替代品?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2007685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:39:00  来源:igfitidea点击:

PHP alternatives?

phpscripting

提问by Tower

Are there alternatives to PHP that perform faster and have somewhat the same feature set (like support for common RDBMS, Curl, Regex, etc)?

是否有 PHP 的替代品可以更快地执行并具有相同的功能集(例如支持常见的 RDBMS、Curl、Regex 等)?

What about coding websites in C? How does that work out? Is that platform independent and works on each server?

用 C 编写网站怎么样?这是怎么做到的?该平台是独立的并且适用于每台服务器吗?

采纳答案by symcbean

"Are there alternatives to PHP" - Yes

“是否有 PHP 的替代品” - 是的

"...that perform faster..." - Yes

“......表现得更快......” - 是的

"...the same feature set..." - No - that would make PHP redundant.

“...相同的功能集...” - 不 - 这会使 PHP 变得多余。

You're asking a very broad question. There are lots of languages out there which support all sorts of DBMS, PCRE and other stuff too.

你问的是一个非常广泛的问题。有很多语言支持各种 DBMS、PCRE 和其他东西。

"What about coding websites in C? How does that work out? Is that platform independent and works on each server?"

“用 C 编写网站怎么样?它是如何工作的?那个平台是独立的并且可以在每个服务器上运行吗?”

  • No it's not platform independent.
  • 不,它不是平台独立的。

Its rather difficult to point you in a specific direction based on such a broad ranging question.

基于如此广泛的问题,很难为您指明特定的方向。

You might want to read this:

您可能想阅读以下内容:

http://benchmarksgame.alioth.debian.org/

http://benchmarksgame.alioth.debian.org/

But note that most of the cost of software lies in development - hardware is cheap - so being able to implement something in half the lines of code will be massively more beneficial for most people than doubling the performance.

但是请注意,软件的大部分成本都在于开发——硬件很便宜——所以能够用一半的代码行来实现一些东西对大多数人来说比将性能提高一倍要大得多。

There are also less obvious constraints and/or advantages in usuing specific languages - e.g.

使用特定语言也有不太明显的限制和/或优势 - 例如

http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html

http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html

C.

C。

回答by miku

Your question is broad.

你的问题很广泛。

  • PHP can be made fast and scalable (Flickr, Facebook and more sites run PHP)

  • Somewhat similar in purpose are webframeworks like Ruby on Rails, Django, Lift, ... (these can scale, too, see e.g. Twitter)

  • A short intro on CGI in C: http://www.cs.tut.fi/~jkorpela/forms/cgic.html

  • PHP 可以变得快速且可扩展(Flickr、Facebook 和更多网站运行 PHP)

  • Ruby on Rails、Django、Lift 等网络框架的用途有些相似(这些也可以扩展,例如 Twitter)

  • C 语言 CGI 的简短介绍:http: //www.cs.tut.fi/~jkorpela/forms/cgic.html

回答by beldaz

If you like Javascript you can use it on the server-side with Node.js

如果你喜欢 Javascript,你可以在Node.js的服务器端使用它

回答by EpicDewd

Perl (CGI)

Perl (CGI)

Python

Python

RoR (Ruby On Rails)

RoR(Ruby On Rails)

ASP (Not the best option)

ASP(不是最佳选择)

Pretty sure if your going to code a website in C your gonna be coding your own webserver too so I'd stay away from that.

很确定如果你要用 C 编写一个网站,你也会编写自己的网络服务器,所以我会远离它。

RoR would be a good option. But it just depends on your personal preference. I tend to stick with php since I know how to do pretty much everything in PHP.

RoR 将是一个不错的选择。但这仅取决于您的个人喜好。我倾向于坚持使用 php,因为我知道如何用 PHP 做几乎所有的事情。

回答by S.Lott

PHP plugs directly into Apache.

PHP 直接插入 Apache。

C does not. To connect C with Apache, you'll have to use some secure/fast CGI implementation instead of the off-the-shelf CGI.

C 没有。要将 C 与 Apache 连接起来,您必须使用一些安全/快速的 CGI 实现而不是现成的 CGI。

C -- as a language -- is a lot of work for building web sites.

C——作为一种语言——是构建网站的大量工作。

Look at Web Frameworks in Python.

看看 Python 中的 Web 框架。

Look at Ruby on Rails.

看看 Ruby on Rails。

回答by magnus

What about coding websites in C? How does that work out? Is that platform independent and works on each server?

用 C 编写网站怎么样?这是怎么做到的?该平台是独立的并且适用于每台服务器吗?

Writing platform independent code in C is quite possible. (PHP itself is written in C, and there are is ridiculous number of cross-platform programs and libraries written in C, like PostgreSQL and MySQL, Boost and Poco C++).

用 C 编写平台独立代码是完全可能的。(PHP 本身是用 C 编写的,而且有大量的跨平台程序和库是用 C 编写的,例如 PostgreSQL 和 MySQL、Boost 和 Poco C++)。

Writing platform independent web applications, on the other hand, primarily depends on how you integrate with the HTTP server. E.g., if you write a C application that integrates directlywith the HTTP server via a compiled module (for Apache or IIS), you're going to end up with less portable code - e.g., writing an IIS module in C or Delphi (which I've seen done, and which eBay originally did) means you are not only locked to Windowsbut you are also locked to IIS on Windows. The situation is similar when writing Apache modules in C.

另一方面,编写独立于平台的Web 应用程序主要取决于您如何与 HTTP 服务器集成。例如,如果您编写一个通过编译模块(用于 Apache 或 IIS)直接与 HTTP 服务器集成的 C 应用程序,您最终将得到可移植性较差的代码 - 例如,用 C 或 Delphi 编写一个 IIS 模块(我已经看到了,而且 eBay 最初是这样做的)意味着您不仅被锁定在 Windows 上,而且还被锁定在 Windows 上的 IIS 上。用 C 编写 Apache 模块时的情况类似。

But if you write a web application in C that integrates via a common standardwith the HTTP server, then yes, you can have quite portable code (albeit code that has to be compiled on each platform). For example, you can use CGI to communicate with the HTTP server using environment variables, or you can use the related standards, FastCGI and SCGI. Again, I've seen this done in practical, commercial applications (both to good effect, and to bad effect).

但是,如果您用 C 编写一个通过通用标准与 HTTP 服务器集成的 Web 应用程序,那么是的,您可以拥有相当可移植的代码(尽管代码必须在每个平台上编译)。例如,您可以使用 CGI 与使用环境变量的 HTTP 服务器进行通信,或者您可以使用相关标准 FastCGI 和 SCGI。同样,我已经在实际的商业应用程序中看到了这一点(既有好的效果,也有坏的效果)。

The debate on native web applications (e.g., written in C, C++ and the like) vs. interpreted web applications (PHP, Perl, etc) often focus on three areas.

关于原生 Web 应用程序(例如,用 C、C++ 等编写)与解释型 Web 应用程序(PHP、Perl 等)的争论通常集中在三个方面。

  • Code performance. Unless it is written by a brain-dead monkey who didn't get the job for writing fortune cookies, C code will always outperform PHP. However, the bottleneck in your application may not be with the speed and memory consumption of the code, but rather with the input/output routines.
  • Developer productivity. Unless you use a good framework (and part of your question was about feature sets of other languages) you're going to be writing a lot of boiler-plate, repetitive code. E.g., decoding percent-encoded URLs, parsing HTTP POST data, etc. There are frameworks that exist for this in C and C++ (see CppCMS).
  • Portability, as you have mentioned. If you're dead set on writing a web application in C, I would stick with CGI or SCGI.
  • 代码性能。除非它是由一个没有得到编写幸运饼干的工作的脑残猴子编写的,否则 C 代码将永远胜过 PHP。但是,应用程序中的瓶颈可能不在于代码的速度和内存消耗,而在于输入/输出例程。
  • 开发人员生产力。除非您使用一个好的框架(并且您的问题的一部分是关于其他语言的功能集),否则您将编写大量样板、重复的代码。例如,解码百分比编码的 URL,解析 HTTP POST 数据等。在 C 和 C++ 中存在用于此的框架(请参阅 CppCMS)。
  • 便携性,正如你所提到的。如果您一心想用 C 编写 Web 应用程序,我会坚持使用 CGI 或 SCGI。

回答by Thilo

If your problem is a website or web application that seems too slow, switching languages is probably not worth the effort. There are much more efficient ways to speed things up. One of them would be code caching to avoid the overhead of a fresh compile of your PHP scripts on every page requests. See for example http://en.wikipedia.org/wiki/PHP_accelerator. I've personally used XCache to great effect.

如果您的问题是网站或 Web 应用程序看起来太慢,那么切换语言可能不值得。有很多更有效的方法可以加快速度。其中之一是代码缓存,以避免在每个页面请求上重新编译 PHP 脚本的开销。参见例如http://en.wikipedia.org/wiki/PHP_accelerator。我个人使用 XCache 效果很好。

There are many other reasons for websites performing slower than they could, many completely unrelated to the underlying language. YSlow (http://developer.yahoo.com/yslow/) is an indispensable tool to find your bottleneck. To give but one example, combining multiple CSS or JS files included from a HTML page into a single file each can dramatically improve response times.

网站执行速度慢于其可能的原因还有许多其他原因,其中许多与底层语言完全无关。YSlow ( http://developer.yahoo.com/yslow/) 是寻找瓶颈不可或缺的工具。仅举一个例子,将 HTML 页面中包含的多个 CSS 或 JS 文件合并到一个文件中,每个文件都可以显着提高响应时间。

So bottom line: In most cases, the underlying language is not the culprit. Having said all that, yes, there are faster languages. See the other answers above :)

所以底线:在大多数情况下,底层语言不是罪魁祸首。话虽如此,是的,有更快的语言。请参阅上面的其他答案:)