PHP Server Sent Event (SSE) Not Working In My New Hosting Server

Viewed 237

I have SSE script which reads feed stream from the remote server. That remote server serves all the output in return. My script is working fine to my other servers and even into local pcs using localhosts.

However, when I use the same script to my new server it is not working and keeps loading.

NEW SERVER DETAILS, WHERE MY SSE CODE IS NOT WORKING

  • cURL is working fine into the new server, I tested by doing call without sse
  • The new server is CentOS 8
  • Apache/2.4.37
  • PHP Version 7.4.2 and it's working fine
  • There is no issue with SSL but just for information SSL is installed

Following is my code which is working fine to my all other servers and into local hosts.

Note: I have replaced username, password and remote server URL with dummy one. But I am using the same script to a new server with all the correct details.

<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');

$gwuser        = "USERNAME";        
$gwpass        = "PASSWORD";

if(!empty($gwuser) && !empty($gwpass)){
        $url = 'https://example.com/gateway/stream';    

        ini_set('output_buffering', 'off');
        ini_set('zlib.output_compression',false);
        ini_set('implicit_flush',true);

        while (@ob_end_flush());
        ob_implicit_flush(true);

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_USERPWD, $gwuser . ':' . $gwpass);

             $error  = 0;

            //This while loop is only for server timeout after 5 minutes
            while(true) {
                $result = curl_exec($ch);
            }

    }
?>  

Please note that normal sse is working where i can continuously print current server time, So i doubt its failing while doing cURL call to remote server. Also into remote server there are no firewall or domain level filter enabled.

Any help or suggestions are appreciated. Thanks

0 Answers
Related