title: Bind socket, and recvfrom in separated functions
body: <p>I'm trying to receive UDP data from a game. And update it on the page constantly. Using JSON to retrieve the data from a function.</p>
  
  <p>Is it possible to separate socket_create/socket_bind from socket_recvfrom?</p>
  
  <p>(I've cut some unnecessary code out of it)</p>
  
  <pre><code>private $socket;
  
  public function socketConnect($port)
  {
  
      $ip = '0.0.0.0'; // local IP
      $port = 20777; // port to listen
  
      $this-&gt;socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
      socket_bind($this-&gt;socket, $ip, $port) or die("Could not connect");
  
     return view('telemetry');
  }
  
  public function getData()
  {
     while (socket_recvfrom($this-&gt;socket, $buf, $bytes, 0, $remote_ip, $remote_port)) {
        // do something
        return response()-&gt;json($data);
      }
  }
  </code></pre>
  
  <p>I've tried setting $this->socket to keep the data but that doesn't seem to work.</p>