如何在php中循环URL和流数据

时间:2016-08-26 05:25:49

标签: php curl server-sent-events

您好我正在使用php尝试服务器发送事件,我有一个https网址,我在每个操作中获取流数据。我需要运行一些脚本,我需要24/7全天候获取数据流。

脚本应该始终在后台运行。

<?php 
   $ch = curl_init('https://api.abc.com:8100/update-stream/connect');    
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_VERBOSE, true); 
   $response = curl_exec($ch);       
   print_r($response);
?>

如何将此curl作为服务器发送事件,始终运行并检查更新?

1 个答案:

答案 0 :(得分:3)

这件事可以帮到你。

<?php
   header("Content-Type: text/event-stream");
   header("Cache-Control: no-cache");
   header("Connection: keep-alive");

   while (true)
   {  
        //your logic can go here
   }  

?>