0

I have a simple JS code (running on the client side, inside NodeJS). That code does a POST to a PHP file that creates a PDF based on the POST data and sends it back to the client.

Is it possible to make some sort of proxy that would let me replace my current PHP file and let me upload it to another server, keeping the same functionality?

What I'm trying to ask is if it is possible to redirect the POST (with it's data) to another server and stream back the reply? (the alternative would be to get the reply, saving in locally, and then stream the already saved file from the reply to the client).

alexandernst
  • 14,352
  • 22
  • 97
  • 197
  • Yes it is possible. Curl can post to an url and you can get the return of it. Have you tried it ? Where are you stuck ? Show us what you have tired so far. – β.εηοιτ.βε Apr 12 '15 at 22:36
  • @b.enoit.be The tricky part is the streaming of the reply without saving it previously. I mean, a real-time proxy that would literally stream the reply from the "other" server to the client. – alexandernst Apr 12 '15 at 22:37
  • `curl_exec()` does return the [content responded](http://stackoverflow.com/questions/6516902/how-to-get-response-using-curl-in-php). As for streaming it, it firstly depends what the server you forward to can do. – β.εηοιτ.βε Apr 12 '15 at 22:41
  • @b.enoit.be Both servers are mine, so... the second server can do what I want it to do. Back to the "real-time streaming", is it possible with php/curl? – alexandernst Apr 12 '15 at 22:42
  • You're talking about a flow like this? Client requests from Server A -> Server A checks that the required post data is present -> Server A makes a CURL request to Server B -> Server B returns the PDF -> Server A returns the CURL results (PDF) to Client – scrowler Apr 12 '15 at 23:12
  • @scrowler More like: Client asks server A for PDF (let's assume PDF is 1GB big). Server A redirects/proxys to server B. Server B generates the 1GB PDF file and starts sending it to server A, which immediately starts sending it to the client. – alexandernst Apr 12 '15 at 23:18
  • Could you achieve this with network infrastructure rather than code? – scrowler Apr 12 '15 at 23:19
  • @scrowler I could, but I'm half curious half decided to do it programatically. – alexandernst Apr 12 '15 at 23:22

0 Answers0