Considering usage of server-side JavaScript [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Recently, i heard alot of JavaScript being used sever-side. Node.js, express.js and similiar stuff are mentioned more and more, but i never had the muse or time to dig deeper into the topic.
Now, as the information flood would not decrease, i can not longer ignore those circumstances.
I wonder about two things:
Can i replace my complete, simple PHP backend, which is primary used only for database access, with server-side Javascript
and if yes:
are there any benefits of doing so?
and if not:
Why is there such a hype?
The topic seems to be quite complex and not too easy to learn, but as time goes by, i more and more get the feeling that this maybe will be the future of backend coding.

Yes you can.
If you are primarily serving data, a more contemporary approach would be to use node.js to implement a restful api . Node.js is particularly suited for this as it inherently works asynchronously - which means each request to the data source (ie the database) inherently does not block while the server is waiting to return, allowing it to punch well above it's weight in terms of being efficient when servicing many requests.
You could use the node modules express.js or restify.js to implement this.
A warning though - node.js is a single threaded application which means some work has to be carried out before is scale able. There are some good solutions for this, such as using Amazon Elastic beanstalk. But as node.js is a relative newcomer many other proposed solutions may need some coaxing to be production ready.
You may find it beneficial to read 'Javascript the good parts' by Douglas Crockford before you begin - something I needed to bring my knowledge of Javascript to a level where I could write quality maintainable code for node.js

Yes you can replace it.
Main concepts about Node you have to know is being async, second is being event-driven.
So if your PHP app just accesses db and serve responses back, node.js would be more efficient in such applications, as would not block idling for response from db, but can process with other requests and so on.
It is not complicated, if you do it. Just go and dive into. Don't ask - prototype. It is the best way to understand if you really need it or not.
I've replaced all my PHP need to node.js, except templating.

Related

PHP vs NodeJS - text based RPG [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I know this isn't a very good question to ask because people may give bias answers, but was wondering if someone could list the pros and cons of using PHP vs NodeJS as a backend language in developing the average text-based online RPG.
The RPG will store its data in a MySQL database and will have typically 10-20 players online simultaneously.
For the long-run, which language would you think is more suitable?
I have several years of experience in PHP and barely any experience in NodeJS. It seems PHP has really good synergy with MySQL but I've been really hearing good things about NodeJS. Also, what design approach should I take (i.e. MVC).
Would be great to hear from someone who has a lot of experience in both languages.
Node.js is not a language. The language is Javascript.
Both are perfectly good choices, the main difference is the asynchronous approach of everything nodejs related. This increases the performance and scalability, but it's harder to debug and uglier to write and read (Learn about the callback hell). You need to get the asynchronous concept very well if you want to have the advantages people usually credits nodejs with.
This being said, you can program asynchronously with PHP, but it's far less common.
So if you are confident with PHP, you need the results fast or don't want to experiment go with it. If you want to learn or experiment, go with Node.
If the limit is 10-20 simultaneous players the performance shouldn't be such a a problem.
About the design approach, I would leave the details for last. MVC is very common and you will probably use something like that to organize your code but the choice depends on lots of factors and you should probably think about this after having the use cases / stories of your application defined and limited.

a website design : how do I combine node.js with php? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am planning to make a website which shows location information up.
The thing is, since the pages will be interactive to users and I am thinking of using node.js and mongoDB(pretty capable for node.js isn't it?).
Please recommend me which languages are fitting on node.js & mongoDB.
Python? or should I use jade for the development?
and plus, will be PHP Codeigniter helpful?
(I am used to developing with PHP and I am wondering if PHP & node.js combination is nice)
Thanks in advance.
Generally I'd prefer not to use two different languages for comparatively simple applications (if your usecase is simple). There might be usecases where you can't avoid this, for example you have to use libraries that only exist in either one of the languages.
I'd use Jade with ExpressJS as Backend, however I consider the template language to be a highly personal Choice. See http://expressjs.com/api.html for an ExpressJS example
See https://npmjs.org/browse/depended for a list of popular NodeJS packages. Some people prefer to use EJS (embedded javascript) or ECO (embedded coffeescript) or one of numerous other templating systems instead of Jade.
Please also consider to use CoffeeScript instead of writing the JS yourself (CoffeeScript is automatically converted into JS. It adds some neat features that are easy to get wrong when you're writing plain JS.
From a performance standpoint, NodeJS is best when you have many API calls that return a small amount of data. I've made good experiences with ExpressJS performance using Jade as backend.
I can recommend the NodeJS beginner book, however, this is, as always, highly subjective.
It's difficult for me to Judge if Python might be a better solution. I recommend you take a look at Tornado together with Jinja2 as template engine. NodeJS can sometimes get quite a callback hell, because of the way it does its asynchronicity, see e.g. http://callbackhell.com/
Note that in any case, for increased security and fast static file (CSS, JS) delivery, you might want to add a reverse proxy layer (Nginx usually provides better performance, but Apache works as well) before the NodeJS/Python server.

PHP or JSP(server side) and Java-Android(Client side) [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I know a little java, android languages.
Now I want to build an Android server-client application and for
client side I will use Android(java) and for server side either
JSP/servlet or PHP.
So I have 2 questions:
What is easier and faster to learn PHP or JSP/servlet(also don't
forget that I also know java) ?
2)Which one would work better? as the client side would be written
in Android(java) may be the JSP/servlet would work better, or it
doesn't matter?, and as PHP is the most used server language may be
it would work better?
Thank you in advance.
I personally found PHP simpler and easier to learn, BUT i knew JAVA and C++ before. I would also like to add that a few of my colleagues that had little experience with other programming languages found PHP to be fun and easy to learn. You have much less to worry about memeomry consumption, variables types, Threads etc...
It totally depends on what your system will require.
-Java is more complex and thus offers a wider range of possibilities, more control etc...
It doesnt mater in what programming language the client application is written in, since client/server communication is done using "standard protocols and systems and formats", such as REST protocol, JSON data encoding and so on....
Another advantage of PHP is that it will run on basically any hosting you purchase for your server, since most of them if not all support PHP/mySQL, while Java will probably require you to purchase a Cloud service or something similar. In such sense PHP may come cheaper to you.
I would also like to add that i have used PHP in most server apps i made, one example was a trading app...but some apps that needed multithreading + RAM caching + hash maps + sockets + other Java functionalities that are built in, etc were meant for Java...so PHP can do the work, but for some things Java is better and just comes naturally...this is totally based on my personal experience so dont take it for granted, you may have a totally different experience.
Maybe tell us what will your app do so we could point you in the right direction.
This

Is Node.js for a web/mobile application like this? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
First of all, I'm an experienced js programmer, good also in php (exluding database design) but don't know much about how servers work.
I'm participating to a quite big projects that's about to start and I'm trying to figure out what's the best tecnology to use.
The application will be geolocalized, and will use google maps. It will have a lot of javascript rendering (probably on the front end I'll end up using backbone or ember, but still thinking). hopefully, it will be used by a lot of users. The will continuously receive data while moving around. Specifically, they'll receive data from clubs, pubs and so on.
hopefully, it will coninuously grow over time, with new features, more data, more users.
I was wondering if node.js could be a good choice for developing it of it would be better to stick to more conventional php ways.
what do you think?
Since you are an experienced Js programmer, you shouldn't have a real problem using Node.js. You're already familiar with the language. If your application will send and receive data continuously, I recommend Node.js and socket.io, which enables real-time communication.
Nodejs takes a lot more initial code than php(because there is no middleware server like apache, you have to program the server yourself), but can perform faster and has much better support for templates and websockets than php. If your maps application wants real time updating, then websockets are incredible, but there is no good solution in php at the moment. The only way to handle websockets in php is through external programs, because you can't control the php server.
One thing to consider if you are going to use nodejs is: Do you like callbacks? Unlike php, where everything is performed synchronously, in nodejs, almost everything is written in asynchronous callbacks, to prevent the server from seizing up while handling a big request. Some people like this coding style, others despise it and think it is a messy bunch of functions inside of functions inside of functions. I personally like this style but it is more complicated than php.
A lot of the choice depends on your team's personal preference. Spend a hour or two trying both with your team and seeing which appears to be working best for you.

PHP or Lift framework for a web application? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm currently developing a web application using PHP, but I'm considering developing the web application using the lift framework instead, because twitter and foursquare have implemented it. I know a few benefits using lift/Scala but, could you guys mention some benefits compared to PHP?
Many thanks
Resmus Lerdorf, the inventor of PHP, once said with regards to foursqaure (build with scala/lift) that it's the first site for a long time that doesn't have a single security hole he could find.
If you're having trouble enumerating the reasons why you'd use scala/lift over PHP, you'll probably want to stick with PHP. PHP is a far more mature and supported platform - oodles of documentation, huge community, tons of tools and libraries.
Scala is a great language, but the primary reason it's being used by Twitter and Foursquare is it's ability to work with enormous sets of data on a horizontally scaled architecture. These are very specific problems for these companies, and Scala was chosen for this purpose very deliberately.
As someone who has recently begun learning Scala, the community and documentation is minute compared to PHP's. Especially where Lift is concerned. And things like IDE support is still in it's early stages.
There's really no way to compare the two technologies (very different approaches). If want to use Scala, use it, but you'll probably be investing more time and energy if you're not already proficient (also, some background in Java doesn't hurt). PHP is just PHP, it's so easy to just pick up and use.
If you ask such a question you'd better stay with PHP. Once your project becomes more and more complex and you are fed up with PHP limitations the question will disappear on its own.
But Lift does not have to be the framework of your choice.
You should consider anything except PHP a good language for web applications, but Scala is a pretty excellent one, although it will change the way you think about programming as a whole. Some people can't handle that, so be warned.
PHP advantages:
Is installed even on the cheapest "5ยข-a-month" webhoster.
PHP disadvantages:
The libraries are not stable and change every now and then, often without notice.
The whole language is buggy and generally doesn't work as a sane person would expect.
The documentation is unusable, sometimes wrong, sometimes only understandable with the user supplied usage examples (which are often wrong or not optimal, too).
No quick way to see the implementation of some language-supplied code.
The API is one big mess ... this shouldn't be called API, it should be called MCOBRIM: Messy Collection of Buggy, Random and Ill-named Methods.

Categories