An open API service indexing awesome lists of open source software.

https://github.com/torres-developer/php-reverse-proxy

Reverse Proxy with PHP
https://github.com/torres-developer/php-reverse-proxy

Last synced: about 1 year ago
JSON representation

Reverse Proxy with PHP

Awesome Lists containing this project

README

          

# Reverse Proxy

A reverse proxy with PHP.

# Why?

My school gives to the students access to a server.

We can serve static files and PHP it's also supported. That is why this is in
PHP.

Let's say I created an HTTP server at localhost port 3000 (with PHP, node.js,
...). I can't make people able to access it over the internet because I don't
have privileges to change the Apache server config or whatever to create a
reverse proxy.

I'm trying to use the tools that were given to me :)

# Examples

## The simplest use

It will reverse proxy to `http://localhost:3000/` always.

``` php
sendRequest(serverRequest());
} catch (RequestExceptionInterface $e) {
$method = $e->getRequest()->getMethod();
$uri = $e->getRequest()->getUri();
respond(new Response(
500,
body: "Request `[$method] $uri` failed.",
headers: [
"Content-Type" => "text/plain"
]
));
} catch (NetworkExceptionInterface $e) {
$method = $e->getRequest()->getMethod();
$uri = $e->getRequest()->getUri();
respond(new Response(
500,
body: "Request `[$method] $uri` could not be completed because of network issues.",
headers: [
"Content-Type" => "text/plain"
]
));
} catch (ClientExceptionInterface $e) {
respond(new Response(
500,
body: "Unexpected error occured on the reverse proxy side.",
headers: [
"Content-Type" => "text/plain"
]
));
} catch (\Throwable $th) {
respond(new Response(
500,
body: "Unexpected error occured.",
headers: [
"Content-Type" => "text/plain"
]
));
}

if ($res->getStatusCode() === 404) {
// It might be that the request to possibly reverse proxy didn't start with
// the path of the endpoint defined on the ReverseProxy::__constructor
// earlier in the code.
}

respond($res);

exit(0);
```