jenssegers / php-proxy

A PHP proxy script with https and post support
https://jenssegers.com
933 stars 266 forks source link

Cannot get a simple demo working #31

Closed allantatter closed 6 years ago

allantatter commented 9 years ago

I wanted to create a simple demo to check whether I can get this working so I have 2 blank Laravel installations side by side, I run them locally on OS X with Mamp on domains site1.dev, site2.dev.

I want to proxy requests from site1.dev to site2.dev but when I visit http://site1.dev then it keeps loading forever with no response. However, when I do simple file_get_contents('http://site2.dev') then it goes through and gets response with status code 200 and correct html in response.

I used the example code from readme:

// Create a PSR7 request based on the current browser request.
$request = ServerRequestFactory::fromGlobals();

// Create a guzzle client
$guzzle = new GuzzleHttp\Client();

// Create the proxy instance
$proxy = new Proxy(new GuzzleAdapter($guzzle));

// Add a response filter that removes the encoding headers.
$proxy->filter(new RemoveEncodingFilter());

// Forward the request and get the response.
$response = $proxy->forward($request)->to('http://site2.dev');

// Output response to the browser.
(new Zend\Diactoros\Response\SapiEmitter)->emit($response);

I'm using dev-master version here.

Any ideas?

jenssegers commented 9 years ago

dev-master is still under development, I'll see what I can do this weekend.

jenssegers commented 9 years ago

When I create a custom Request object such as new Request('http://localhost/foo/bar', 'GET'); it does work, but when I use ServerRequestFactory::fromGlobals() it doesn't. Can you check if this is the same problem for you?

allantatter commented 9 years ago

When I created Guzzle's Request and passed it down, then it did work (if I remember correctly). I cannot confirm atm, away from work machine.

allantatter commented 9 years ago

This somewhat works, at least I get response from the app I expect.

//$request = ServerRequestFactory::fromGlobals();
$request = new Zend\Diactoros\Request('http://127.0.0.1:3000', 'GET');

Could you add v2.2.2 tag to commit 1b79a3a (30 May 2015 22:02:26 GMT+3)? At least that one works for me and problem with v2.2.1 is that I depend on Guzzle v6.

tejastank commented 7 years ago

@allantatter I had php7 and like to use most simplest code, but not sure how to use this.

Can you please share code. so when I use proxy in browser it will start to work.

allantatter commented 7 years ago

@tejastank The idea of proxying requests through PHP scripts is evil in its roots (I tried it because I needed the solution super fast to make things just work) :D I'd not recommend using it in production if possible (too large performance hit to the server). Do you have Nginx running behind PHP? Easier to give an advice for that.

tejastank commented 6 years ago

@allantatter thanks mate, I left this right now. use python based my own japranto code, will do use in some future... :)

erlangparasu commented 1 year ago

is there example for nginx config?