Guzzle with Ratchet (Websocket server framework)

336 views
Skip to first unread message

xpdseth

unread,
Apr 27, 2014, 2:24:09 PM4/27/14
to guz...@googlegroups.com
Hi guys I have been puzzled the almost whole day why my POST parameters are not send/recieved into my controller.php.

I have a super simple test file controller.php with the following content --> 

<?php
echo "<pre>POST-->".print_r($_POST,true)."<pre/>";
?>

Now I use Guzzle like this. 
If i run the following code outside the eventloop which Ratchet is creating it works perfectly!
The POST parameters are sent back echoed.

However if i run the EXACT same code from lets say onOpen on a new connection which is actually inside the eventloop
I dont have any error/exception i have the response BACK from my controller.php but the POST this time is empty!


$client = new \Guzzle\Http\Client();
$request = $client->post(
'http://192.168.9.101/www/controller.php', 
array('Accept'=>'application/json'), 
array(
'launch'=>'myFn',
'json'=>json_encode(array(
'key1'=>'val1',
)
)
)
);
$response = $request->send();
echo "<pre>".print_r($response->getMessage(),true)."<pre/>";


I have been debugging the whole day and what i found out is that if i go to 
Ratchet\vendor\guzzle\http\Guzzle\Http\Message\RequestFactory.php

Then change method getInstance to look like this then IT works!!!
My Post parameters are send and everything is OK.

public static function getInstance()
    {
        // @codeCoverageIgnoreStart
        if (!static::$instance) {
          //  static::$instance = new static();  -- NOT WORKING --
          //  static::$instance = new self(); -- WORKING --
            static::$instance = new RequestFactory(); //-- WORKING --
        }
        // @codeCoverageIgnoreEnd
        return static::$instance;
    }
################################

Second option instead of changing the getInstance method if I put the following line
before i go into my event loop. I guess it is becuase the singleton with static will be created
and later on it will just return static:$instance.

new \Guzzle\Http\Client();
 

xpdseth

unread,
Apr 27, 2014, 3:55:18 PM4/27/14
to guz...@googlegroups.com
Hi a little further on the issue.
I decided to put an echo inside each and every function inside 
Ratchet\vendor\guzzle\http\Guzzle\Http\Message\RequestFactory.php
Just for testing this is the result

When getInstance uses -> static::$instance = new static(); - POST params are empty
getInstance
__construct
fromMessage
fromParts
LoginValidator->onOpen (one of mine functions)
getInstance

When getInstance uses -> static::$instance = new self(); - POST params are empty
getInstance
__construct
getInstance
fromMessage
fromParts
create
LoginValidator->onOpen
getInstance
create

Reply all
Reply to author
Forward
0 new messages