开发者

what is the main advantage of server-side javascript?

I just want to know if there is an advantage of using server-side JS? A开发者_开发知识库lso, how can it work with PHP?


i just want to know that what is advantage of server-side js?

It lets you use JS on the server. (Which lets you reuse existing JS skills and code, and has all the usual benefits of JS (event driven programming, powerful lambdas, etc).

And how it works with php?

Generally speaking, it is used instead of PHP.


Javascript has an excellent event programming model thanks to it's callback functionality. This makes it great for server side coding.

First event driven model is great for large requests to be taken care of. In a typical Apache server, every client request spawns off a new thread. 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.


I would say one main advantage of using server-side javascript (and this applies not just to php but any other server-side language -- e.g. Java) is that it allows you to customize certain aspects of your execution. 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. 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.


You can use Apache 2.4 event mpm and TeaJS for a setup similar to your Apache/mod_php setup. See http://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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜