简体   繁体   English

服务器端 javascript 的主要优势是什么?

[英]what is the main advantage of server-side javascript?

I just want to know if there is an advantage of using server-side JS?我只想知道使用服务器端JS是否有优势? Also, how can it work with PHP?此外,它如何与 PHP 一起使用?

i just want to know that what is advantage of server-side js?我只想知道服务器端js的优势是什么?

It lets you use JS on the server.它允许您在服务器上使用 JS。 (Which lets you reuse existing JS skills and code, and has all the usual benefits of JS (event driven programming, powerful lambdas, etc). (这让您可以重用现有的 JS 技能和代码,并具有 JS 的所有常见优点(事件驱动编程、强大的 lambda 等)。

And how it works with php?以及它如何与 php 一起工作?

Generally speaking, it is used instead of PHP.一般来说,它是用来代替PHP的。

Javascript has an excellent event programming model thanks to it's callback functionality. Javascript 具有出色的事件编程 model,这要归功于它的回调功能。 This makes it great for server side coding.这使得它非常适合服务器端编码。

First event driven model is great for large requests to be taken care of.第一个事件驱动的 model 非常适合处理大型请求。 In a typical Apache server, every client request spawns off a new thread.在典型的 Apache 服务器中,每个客户端请求都会产生一个新线程。 So your server is generated large number of threads for requests EVEN if some threads are just sitting idle waiting for some taks.因此,即使某些线程只是闲置等待某些任务,您的服务器也会为请求生成大量线程。 This is surely not ideal.这肯定不理想。

With event driven programming, you can register events and once the results return from the database, event calls are made.使用事件驱动编程,您可以注册事件,一旦从数据库返回结果,就会进行事件调用。 So idle time is less and thread footprint is minimal.因此空闲时间更少,线程占用空间最小。 (note: it's not an alternative to asynchronous programming, which has it's own advantages). (注意:它不是异步编程的替代方案,它有自己的优势)。

And yes, it is used INSTEAD of PHP.是的,它被用来代替 PHP。

You can use Apache 2.4 event mpm and TeaJS for a setup similar to your Apache/mod_php setup.您可以使用 Apache 2.4 事件 mpm 和 TeaJS 进行类似于 Apache/mod_php 设置的设置。 See http://qteajs.orghttp://qteajs.org

Two of the advantages I don't see mentioned here are enhanced performance (V8 compiles the code) and maintainability (you are using the same language on the client and server side)我在这里没有提到的两个优点是增强的性能(V8 编译代码)和可维护性(您在客户端和服务器端使用相同的语言)

I would say one main advantage of using server-side javascript (and this applies not just to php but any other server-side language -- eg Java) is that it allows you to customize certain aspects of your execution.我想说使用服务器端 javascript 的一个主要优点(这不仅适用于 php,而且适用于任何其他服务器端语言——例如 Java)是它允许您自定义执行的某些方面。 So you can have your normal execution flow but provide some "hooks" in the code where you allow JavaScript code to get executed and change certain values/conditions -- which might trigger different execution paths.因此,您可以拥有正常的执行流程,但在代码中提供一些“挂钩”,您可以在其中允许执行 JavaScript 代码并更改某些值/条件——这可能会触发不同的执行路径。 This was you can have for instace non-technical people customize certain aspects of your applications without actually having to write server-side code for it, but instead just using a "simple" language like JavaScript.这是您可以让非技术人员自定义应用程序的某些方面,而无需实际为其编写服务器端代码,而只需使用像 JavaScript 这样的“简单”语言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM