I have a PHP Class to push message with socket like :
function __construct()
{
$this->socket = fsockopen($this->host, $this->port, $errno, $errstr, 0); //I tried with 99999 for timeout too
}
function push($params)
{
$req = 'GET /push?'.$params." HTTP/1.1
"
. 'Host: '.$this->host."
"
. "Content-Type: application/x-www-form-urlencoded
"
. 'Content-Length: '.strlen($params)."
"
. "Connection: keep-alive
";
fwrite($this->socket, $req);
}
But if I tried to push 2 or more message, only one is receive by NodeJS serveur :
foreach(['foo=2', 'bar=42'] as $loop)
{
$pusher->push($loop);
}
Now, if i put this line $this->socket = fsockopen($this->host, $this->port, $errno, $errstr, 0);
just before fwrite
, all messages will be send...
So why I can't use only one connexion for multiple request with same soket?
I use "keep-alive" and I don't call fclose
, so I don't understand why my nodeJS server receive only one message in first case...