Posts

Showing posts with the label Apache

Apache X-Forward-For settings for behinding reverse proxy

Add following settings into your httpd.conf or the configuration file in sites-available that linked to sites-enabled. LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy  SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded  CustomLog "logs/access_log" combined env=!forwarded CustomLog "logs/access_log" proxy env=forwarded After saving the settings, restart your httpd and you should see the real client IP in access log.

How to implement a real-time chat server in PHP using Server-Sent Events (update: added C benchmark)

Lessons learned: A web server written in PHP can give more than 10000 req/s on small hardware A web server written in PHP is not slower than being written in Java (without threads) A web server written in PHP is 30 percent slower than being written in C (without threads) Realtime applications can be developed in PHP without problems PHP normally runs inside a web server like Apache or nginx. This keeps all requests separate from each other and does not allow sharing memory or connections. To implement a chat server, the browser has to poll the server regularly for new data. The data is stored in a database and looked up for each request. This is very slow, takes a lot of resources on the server and does not give messages in realtime. Newer browsers support data being pushed from the server to the client. There are two techniques used: WebSockets (full-duplex) and Server-Sent Events (push notifications) Using these techniques, one connection stays open for each client and the server...