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
- Host: GitHub
- URL: https://github.com/torres-developer/php-reverse-proxy
- Owner: torres-developer
- License: agpl-3.0
- Created: 2023-04-21T15:40:21.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-23T00:29:24.000Z (about 3 years ago)
- Last Synced: 2025-01-22T21:14:45.420Z (over 1 year ago)
- Language: PHP
- Size: 46.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
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);
```