title: PHP curl sending message to Node.js returns no result
body: <p>I wanted to implement websockets to a complex web system to synchronize data properly. The idea was that all clients may make ajax-calls, php handles those calls, may edit data on a database and on success the php-backend sends some data to a websocket-server. That websocket server then sends the data to all subscribed clients, which may be interested in the data.</p>
  
  <p>So far clients can subscribe to the websocket server (socket.io) but I can't figure out how to make php send messages to the websocket server.</p>
  
  <p>So far my websocket server looks like this:</p>
  
  <pre><code>const fs = require('fs');
  
  const credentials = {
    key: fs.readFileSync('C:/xampp/apache/conf/ssl.key/server.key'),
    cert: fs.readFileSync('C:/xampp/apache/conf/ssl.crt/server.crt')
  };
  const app = require('express')();
  
  
  
  // var server = require('https').Server(app);
  let server = require('https').createServer(credentials, app);
  let io = require('socket.io')(server);
  
  server.listen(3000);
  
  io.sockets.on('connection', function(socket){
      console.log("connected");
      socket.emit('test', { hello: 'world' });
      socket.on('some other event', function (data) {
          console.log(data);
      });
  
      socket.on('subscribe', function(room) {
          console.log('joining room', room);
          socket.join(room);
      });
  
      socket.on('unsubscribe', function(room) {
          console.log('leaving room', room);
          socket.leave(room);
      });
  
      socket.on('send', function(data) {
          console.log('sending message');
          io.sockets.in(data.room).emit('message', data);
      });
  });
  </code></pre>
  
  <p>And my php-calls look like this:
      
  
  <pre><code>require_once __DIR__.'/../vendor/autoload.php';
  $dbHandler = \services\DBHandling::getInstance();
  
  
  $data = [
      "subscribe" =&gt; "room3",
      "message" =&gt; "evacuate nuclear reactor block B !"
  ];
  $data_string = json_encode($data);
  
  $curl = curl_init("http://localhost");
  
  curl_setopt($curl, CURLOPT_HEADER, true);
  curl_setopt($curl, CURLOPT_HTTPHEADER,['Content-Type: application/json',
      'Content-Length: ' . strlen($data_string)
  ]);
  
  curl_setopt($curl,CURLOPT_PORT, 3000);
  curl_setopt($curl,CURLOPT_POST,true);
  curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($curl,CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($curl,CURLOPT_CONNECTTIMEOUT, 2);
  curl_setopt($curl,CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
  curl_setopt($curl,CURLOPT_POSTFIELDS,$data_string);
  
  $json_response = curl_exec($curl);
  $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  
  if ($status != 200) {
      print_r([
          'Error',
          $status,
          curl_errno($curl)
      ]);
  }
  curl_close($curl);
  </code></pre>
  
  <p>The php-backend only needs to send messages to the websocket server and doesn't need to receive any.</p>