Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: X-Sendfile example #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
{
# This file is only used for dev and benchmarking.
# Please see /etc/Caddyfile in the container, for the one that is actual used in this demo

#debug
frankenphp {
worker ./public/index.php
}
}

localhost {
#log
route {
root * public/
#php_fastcgi 127.0.0.1:9000
php_server
log

root * public/

request_header X-Sendfile-Type x-accel-redirect
intercept {
@sendfile header X-Accel-Redirect *
handle_response @sendfile {
root * private-files/
rewrite * {resp.header.X-Accel-Redirect}
method * GET
header -X-Accel-Redirect
file_server
}
}

php_server
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Run the project with Docker (worker mode):
```console
docker run \
-e FRANKENPHP_CONFIG="worker ./public/index.php" \
-v $PWD/Caddyfile:/etc/caddy/Caddyfile \
-v $PWD:/app \
-p 80:80 -p 443:443/tcp -p 443:443/udp \
--name FrankenPHP-demo \
Expand Down
16 changes: 16 additions & 0 deletions benchmark.Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
# This file is only used for benchmarking.
# Please see Caddyfile, for the one that is actual used in this demo

frankenphp {
worker ./public/index.php
}
}

localhost {
route {
root * public/
#php_fastcgi 127.0.0.1:9000
php_server
}
}
2 changes: 2 additions & 0 deletions config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ framework:
#csrf_protection: true
handle_all_throwables: true

trust_x_sendfile_type_header: true

# Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support.
session:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class HomepageController extends AbstractController
class MainController extends AbstractController
{
#[Route("/", name: "homepage")]
public function index(): Response
Expand All @@ -15,4 +16,13 @@ public function index(): Response
'controller_name' => 'HomepageController',
]);
}

#[Route("/download-logo", name: "download_logo")]
public function downloadLogo(): BinaryFileResponse
{
$response = new BinaryFileResponse(__DIR__.'/../../private-files/frankenphp.png');
$response->headers->set('Content-Type', 'image/png');

return $response;
}
}
1 change: 0 additions & 1 deletion static-build.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ RUN echo APP_ENV=prod > .env.local ; \
# Build the static binary
WORKDIR /go/src/app/
RUN EMBED=dist/app/ \
PHP_EXTENSIONS=ctype,iconv,pdo_sqlite \
./build-static.sh