HTTP libraries/HTTP server

Asked

Viewed 118 times

0

My question is about web servers and libraries focused on protocol HTTP.

In PHP you can use "apache" as a web server, but in other languages the same stack is used? This doubt came to me when researching languages like: Go, Crystal, Hack, Ruby and Python.

I saw that in them libraries are focused on the protocol HTTP, on them you create your own web server, serving yourself or is an add-on to apache (for example)?

It would be like you create your own "requisitions" structure, shaping as your need?

I always kept this doubt, I know you will always need a web server, but I do not know if it will always be fit apache or Nginx (the ones I know).

Example:

 Código tirado do site: cystal-lang.org
 
 require "http/server"

 server = HTTP::Server.new(8080) do |context|
  context.response.content_type = "text/plain"
  context.response.print "Hello world, got #{context.request.path}!"
 end

puts "Listening on http://0.0.0.0:8080"
server.listen

Grateful

  • Apache is one of the options. You could use PHP in Nginx, Lighthttpd and a multitude of other servers (and for testing, even PHP alone). It works even in IIS, although it is not a combination of the best. As for creating a structure of its own, it only depends on the purpose. I have things running in PHP, but for some things more punctual, I made a server of my own, for higher performance. It is a unique executable, which makes all the HTTP part, and the working logic. Same thing for Websockets. I chose one of my own to facilitate integration with other things of mine.

  • Detail: nothing would prevent me from making requests to PHP on my own server via CGI or something like that. HTTP is an extremely simple protocol. Care is in the details, and it’s hard to take care of file caching and modification, but no big secrets. HTTPS is more boring, but it has libraries open to it

  • I understood, php was an example, because I saw nothing related to creating your own server on it, always apache or others. In the case of other languages, is this assumed? Or I have to create my own server, ex in ruby or go, since they have HTTP libraries and most examples are, "look how simple it is to create an http server".

  • This varies widely.

1 answer

0

It wouldn’t be like Apache since built-in servers are quite limited, full servers like Apache have numerous settings and extra features that built-in servers don’t have. They usually serve for quick testing or simplistic implementations. PHP itself has a built-in server, you can activate this feature by running the following command:

php -S localhost:8000

To better understand the above command read this page

  • Correct, I understand the difference between the embedded servers or even the packages like xampp and etc. A doubt itself, this out of php context and yes in a general context. What I meant: In PHP you can use "apache" as a web server (production), but in other languages ? PHP has this "ease" of running the scripts (that’s what I read in surveys). This doubt came to me because certain languages like "ruby" have a library aimed at the http protocol. You would develop your own server or still need to run a server like apache?

  • Each language has its server, in Python you can sweat Apache or lighttpd or even NGINX. Ruby has Puma Web Server. In this way each language has its production server, and almost all have built-in servers for small tests

  • In case, then these HTTP libraries are to develop embedded servers for development use? Like the Go or Ruby HTTP library.

  • In large part yes, because they do not have advanced features to handle many accesses or even great security in terms of access to disk files.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.