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();