Server Sent Events With Codeigniter 4 |
I am trying to update the progress of a long running php script on frontend using server sent events.
But am only receiving first few eventstreams and thereafter there is error. I am Sharing code below; Html View: Code: <a href="#" onclick="startScraping()" >START SCRAPING</a> Home Controller: PHP Code: <?php namespace App\Controllers; Common.php file: PHP Code: function sendMsg($id, $message, $progress) Here this loop is not fully executed. I am only receiving first few rows as response. There after am getting this error id:1608816937 data:{"message":"1 row(s) Processed.","progress":0} <br /> <b>Fatal error</b>: Uncaught ErrorException: Cannot modify header information - headers already sent by (output started at /var/www/webScraper/app/Common.php:130) in /var/www/webScraper/system/Debug/Exceptions.php:164 Stack trace: #0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'Cannot modify h...', '/var/www/webScr...', 164, Array) #1 /var/www/webScraper/system/Debug/Exceptions.php(164): header('HTTP/1.1 500 In...', true, 500) #2 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ErrorException)) #3 {main} thrown in <b>/var/www/webScraper/system/Debug/Exceptions.php</b> on line <b>164</b><br /> <br /> <b>Fatal error</b>: Uncaught ErrorException: Cannot modify header information - headers already sent by (output started at /var/www/webScraper/app/Common.php:130) in /var/www/webScraper/system/Debug/Exceptions.php:164 Stack trace: #0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'Cannot modify h...', '/var/www/webScr...', 164, Array) #1 /var/www/webScraper/system/Debug/Exceptions.php(164): header('HTTP/1.1 500 In...', true, 500) #2 /var/www/webScraper/system/Debug/Exceptions.php(224): CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ErrorException)) #3 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler() #4 {main} thrown in <b>/var/www/webScraper/system/Debug/Exceptions.php</b> on line <b>164</b><br /> What am i doing wrong?
Sounds like your re-sending the headers again hard to tell by the code fragments.
Check your headers they should only be sent once. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
PHP Code: headers already sent by (output started at /var/www/webScraper/app/Common.php:130) Often the error for header already sent means there’s an error message that was printed. What do you have on line 130?
(12-24-2020, 01:30 PM)includebeer Wrote: echo "id:". $id . PHP_EOL; this is the code i have on line 130 on common.php file. complete function is as below PHP Code: function sendMsg($id, $message, $progress) |
Welcome Guest, Not a member yet? Register Sign In |