Download the PHP package tempcord/http without Composer

On this page you can find all versions of the php package tempcord/http. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package http

Tempcord HTTP

An HTTP server that runs inside the bot, on the same event loop as the gateway, for the Tempcord Discord bot framework.

Installation

A route

That is the whole registration. Routes are discovered like commands and listeners, built by the container, and served as soon as the bot boots.

Why in the bot rather than behind PHP-FPM

Because of what a handler can reach. The gateway lives in a long-running process; a request handled by FPM is a different process entirely, with no access to the connection, the guild cache, or anything the bot learned this minute. It could only do what any outside script could do — call the REST API and hope.

Served here, a route shares the container, the database, the cache and the live connection:

The cost is the other side of the same coin: a handler that blocks blocks the gateway too. That is the bargain every other part of a Tempcord bot already makes, and the reason a slow handler should await rather than sleep.

Named segments

A handler takes what it asks for, in whatever order: a parameter typed as Request is given the request, and every other one is given the segment of the same name.

A segment matches anything but a slash, so /guilds/{guild} does not swallow /guilds/1/members. A literal path always wins over one with a segment, so /guilds/mine works whichever order the two are discovered in.

Answers

A handler returning nothing answers 204. A handler that throws is logged and answers 500 with nothing else — an exception message is not something to hand to whoever is on the other end of the socket.

A path that exists under a different method answers 405, not 404: the difference is the whole of "you asked wrongly" versus "there is nothing here", and it is what somebody debugging a webhook needs to see.

Reading a request

json() answers null rather than throwing: a body that is not what was expected is an ordinary thing to receive from the open internet, and a handler replying 400 reads better than one wrapped in a try.

Middleware

The first one listed is outermost. Returning an answer instead of calling $next stops the request there — the handler never runs, and neither does any middleware behind it. That is the whole reason this exists: a check on whether the caller may be asking has to be able to stop the work, not merely disapprove of it afterwards.

Middleware are built by the container, so they may take whatever they need.

Deciding who is asking

There are no sessions here, and that is deliberate — see below. What there is covers what a bot's HTTP layer actually needs:

Secret compares in constant time. === on a secret stops at the first byte that differs, and that difference is measurable over enough requests — which is how a signature gets guessed one byte at a time by somebody with a loop and patience. signed() takes the raw body, because re-encoding changes bytes and the signature is over what was actually sent.

Cookies go out on the response, with HttpOnly, SameSite=Lax and Path=/ by default. Secure is left to you: a bot behind a plain-HTTP proxy would otherwise set a cookie the browser never returns, which is a bug that looks like a login loop.

Never use PHP sessions here

session_start() and $_SESSION are unsafe in this server, and not in a subtle way. PHP keeps one session per process. Under PHP-FPM that is fine because the process is the request; here the process serves thousands of requests over weeks, so the first caller's session becomes the process's session and every caller after them reads it. With fibers, two requests interleave inside it.

The same goes for $_GET, $_POST, $_COOKIE and $_SERVER: they hold whatever the CLI process started with, not the request being served. And setcookie() and header() write nowhere — the answer is the Response.

For the same reason a handler must not keep state on itself. It is built by the container, which may hand back the same instance next time; the request is given as an argument precisely so that nothing has to be stashed.

Configuration

app/config/http.config.php:

It binds to loopback by default, on purpose. A bot process is not a web server, and a route that reaches the live gateway connection is not something to put on the open internet by accident. Put a reverse proxy in front of it, or set the host deliberately, knowing what is behind it.

Nothing listens when no routes were discovered, and a port already taken is logged rather than thrown — a gateway that will not start because a stale process holds 8080 is a bad trade.

Requirements

License

MIT


All versions of http with dependencies

PHP Build Version
Package Version
Requires php Version ^8.5
tempcord/framework Version >=0.12 <2.0
react/http Version ^1.11
react/socket Version ^1.16
react/event-loop Version ^1.3
react/promise Version ^3
psr/http-message Version ^1.1 || ^2.0
tempest/core Version ^3.18
tempest/log Version ^3.18
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tempcord/http contains the following files

Loading the files please wait ...