title: How to get response from server using curl in php
body: <p>i am using CURL to get data from server. The way it works is like the following:</p>
  
  <ul>
  <li>A device send data to routing application which is found on server.</li>
  <li>To get the data from the routing application, clients must ask with GET method specifying server address, port and parameter.</li>
  <li>once a client is connected, the application start sending data on every new packet arrived from the device to connected clients. see below picture</li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/YzXwl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YzXwl.jpg" alt="enter image description here"></a></p>
  
  <p>now lets see my code that i run to get the response:</p>
  
  <pre><code>&lt;?php
     $curl = curl_init('http://192.168.1.4/online?user=dneb'); 
     curl_setopt($curl, CURLOPT_PORT, 1818); 
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 
     $result = curl_exec($curl);
     curl_close($curl);
     echo $result;
  </code></pre>
  
  <p>With this CURL request i can get the response data from routing application. But the routing application will never stop sending data to connected clients, so i will get the result only if i close the routing application, and it will echo every data as one. Now my question is how can i echo each data without closing the connection or the connection closed by the routing application? i.e When data received, display the data without any conditions. You can suggest any other options to forward this data to another server using TCP. Thanks!  </p>