# Anyone serving PHP-FPM directly from HAProxy?

**URL:** <https://discourse.haproxy.org/t/anyone-serving-php-fpm-directly-from-haproxy/5978>\
**Category:** Experimental\
**Created:** [November 29, 2020, 2:34pm UTC](https://discourse.haproxy.org/t/anyone-serving-php-fpm-directly-from-haproxy/5978 "2020-11-29T14:34:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yosu\_Cadilla](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/yosu_cadilla/32/1310_2.png) [@Yosu\_Cadilla](https://discourse.haproxy.org/u/Yosu_Cadilla)\
**Post date:** [November 29, 2020, 2:34pm UTC](https://discourse.haproxy.org/t/anyone-serving-php-fpm-directly-from-haproxy/5978/1 "2020-11-29T14:34:06Z")

</div>

This is a very interesting feature, wondering if anyone is already doing this and would share some wisdom…

Additionally, could the static content be served from HAProxy directly hence no more need for an HTTP server?

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [November 29, 2020, 5:43pm UTC](https://discourse.haproxy.org/t/anyone-serving-php-fpm-directly-from-haproxy/5978/2 "2020-11-29T17:43:46Z")

</div>

> [@Yosu\_Cadilla](#):
>
> could the static content be served from HAProxy directly hence no more need for an HTTP server?

No, haproxy will never serve files and will never be a replacement for a webserver.

---

<div class="post-metadata">

**Author:** ![Yosu\_Cadilla](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/yosu_cadilla/32/1310_2.png) [@Yosu\_Cadilla](https://discourse.haproxy.org/u/Yosu_Cadilla)\
**Post date:** [November 29, 2020, 10:49pm UTC](https://discourse.haproxy.org/t/anyone-serving-php-fpm-directly-from-haproxy/5978/3 "2020-11-29T22:49:58Z")

</div>

What about the Native Response Generator?  
[https://eleph.haproxy.com/](https://eleph.haproxy.com/)

[![](https://us1.discourse-cdn.com/flex016/uploads/haproxy/original/2X/2/2fe708a70f290072703a6fa4c7e95350e29466d7.jpeg "HAProxy 2.2 - Live Q&A") ](https://www.youtube.com/watch?v=HC_gWRMzBys)

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [November 30, 2020, 8:54pm UTC](https://discourse.haproxy.org/t/anyone-serving-php-fpm-directly-from-haproxy/5978/4 "2020-11-30T20:54:11Z")

</div>

The video explicitly mentions that haproxy is not a replacement for a webserver.

You can serve **the content** of a file with [errorfiles](https://cbonte.github.io/haproxy-dconv/2.2/configuration.html#3.8-errorfile) or [http-request return](https://cbonte.github.io/haproxy-dconv/2.2/configuration.html#4.2-http-request%20return), but:

- in needs to fit 1 buffer (that’s generally 16kb)
- it’s read into memory at startup, if you update the file and want haproxy to start serving the new instead of the old one, you need to reload haproxy

Make no mistake. Haproxy is not a webserver and probably never will be.

---

<div class="post-metadata">

**Author:** ![arlecchino](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@arlecchino](https://discourse.haproxy.org/u/arlecchino)\
**Post date:** [December 2, 2020, 8:41pm UTC](https://discourse.haproxy.org/t/anyone-serving-php-fpm-directly-from-haproxy/5978/5 "2020-12-02T20:41:09Z")

</div>

What’s with using a lua script service to serving files?  
I don’t use it for regularly serving the files of a complete application, but if there is no need for special, flexible configuration, restrictions, serving bigger not-memory-mapped files and other stuff which is already built and proven in a webserver, why not?

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [December 2, 2020, 8:43pm UTC](https://discourse.haproxy.org/t/anyone-serving-php-fpm-directly-from-haproxy/5978/6 "2020-12-02T20:43:16Z")

</div>

You should never ever use LUA to read files from the disk.

> [@How do I serve a single static file from HAProxy?](https://discourse.haproxy.org/t/how-do-i-serve-a-single-static-file-from-haproxy/32/13):
>
> You should never access the file system from LUA. Especially not based on user-triggered requests: The list of prohibited standard Lua functions during the runtime contains all those that do filesystem access: os.remove() os.rename() os.tmpname() package.\*() io.\*() file.\*() You CANNOT emulate a webserver with LUA, those are blocking syscalls, they don’t belong in an event driven software like haproxy. In haproxy 2.2, you can use [http-request return](https://cbonte.github.io/haproxy-dconv/2.2/configuration.html#4.2-http-request%20return) if the errorfile workaround disgusts y…

---

<div class="post-metadata">

**Author:** ![Yosu\_Cadilla](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/yosu_cadilla/32/1310_2.png) [@Yosu\_Cadilla](https://discourse.haproxy.org/u/Yosu_Cadilla)\
**Post date:** [December 13, 2020, 6:38pm UTC](https://discourse.haproxy.org/t/anyone-serving-php-fpm-directly-from-haproxy/5978/7 "2020-12-13T18:38:42Z")

</div>

Thanks @lukastribus  
I understand HAP is not an HTTP server.  
My use case is a fully PHP APP with just the logo and a few other files (some css mostly) as the only static content, hence I was wondering if I could entirely avoid using an HTTP server by serving those little static pieces from HAP directly, as this would greatly reduce my footprint when replicating this APP.

Thanks @arlecchino Worth checking for sure, LUA is not in my skillset, but I’ll find someone who can help. Providing we don’t use any of the blocking syscalls Lukas mentioned, it might work!  
At least it will be a great experiment, even if it does not work/perform well…

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [December 13, 2020, 11:27pm UTC](https://discourse.haproxy.org/t/anyone-serving-php-fpm-directly-from-haproxy/5978/8 "2020-12-13T23:27:00Z")

</div>

All of those are blocking syscalls. You can’t do this.
