DEV Community

Discussion on: Node vs PHP

 
razbakov profile image
Aleksey Razbakov

If you would start a new project, what would you make as your backend? Node or PHP? Express or Laravel? Let's say you write a REST API, what stack would you use and why?

Thread Thread
 
andreidascalu profile image
Andrei Dascalu

I would make my decision based on the goal. For example I have projects that leave a lot of room for learning. I would go with express in this case just to improve my knowledge, but I would also use it in cases where node packages may be superior to php (in case of grpc for example)

Otherwise I would use php but I would not use any of the major frameworks (I have a performance comparison of returning 100k json encoded rows from two related tables, Laravel is the worst performer of all).
I would favor a microservices framework like Swoole if I weren't inclined to make a monolithic API. Otherwise I would use a microframework like Symlex but nowadays I sort of favor a custom solution built around a fast router (there's nikic but also the phpleague router). For an API there aren't many requirements: fast router with Middleware support, DI container (phpdi is excellent) and maybe doctrine for a strong orm with several layers of caching. Of course, logging and some metrics/observability would be nice.
I have a sort of personal 'framework' that rivals symfony 5 in performance but it still lags behind the likes of ubiquity 2 and symlex.
But my main requirement from a php stack would be to handle routing for psr requests and responses and neither symfony nor laravel do that.
This comes from the fact that nowadays I consider it mandatory for a php api to be deployable with roadrunner (symlex is built for roadrunner compatibility), in this case php blows node/express out of the water and can close in on rust performance for example.

Thread Thread
 
tracker1 profile image
Michael J. Ryan

I wouldn't use either for grpc... If you're interested in container orchestration like kubernetes, I might use node for it. You can't use grpc+cluster modules together iirc.