I'm trying to file upload and download in fastcgi.
To use sendfile() I need the web server's open socket to the client (browser).
fastcgi doesn't pass it to me (I don't think).
I'm clueless on how to get the browser's socket descriptor.
I'm also open to another approach without a redirect or opening a new connection.
help is appreciated
You don't get a socket to the browser in FastCGI. The only socket you get directly is connected to the web server, and it's expecting FastCGI data frames, not just raw data.
The most typical solution for file downloads is the X-Sendfile header, which directs the web server to spit out a file (probably using something like
sendfile()internally) instead of your response. It was introduced by Lighttpd, is supported natively by nginx, and is supported by Apache via mod_xsendfile.