===== Server Side Events ===== [[en:adminmanual:businessactions#business_actionlaunch_script|See how coreBOS does it!]] Server side events in coreBOS are very easy to implement. Since you have control of many ways to add javascript code to the application and also many ways to add PHP code, you can insert your EventSource javascript code and call a PHP script via ajax in order for it to send the header and subsequent messages. You can find an example of this in the [[https://github.com/tsolucio/coreBOSIERelations|Import/Export Relations Extension]] which uses SSE to launch the import process and inform the user of the progress of the operation. In that code, you can see that the launchImportProcess() function in coreBOSIERelations.js creates the EventSource object against an AJAX URL to the module, which calls the PHP script cbierelate.php. The messages sent by this script are read by the EventSource object and updated on the screen accordingly. There is a lot of information and many examples of how SSE works on the internet, but I {{ :en:devel:sse.zip |add here a standalone example}} upon which I constructed the code in coreBOSIERelations **es.html**


Results



0
**source.php** $message, 'progress' => $progress ); echo "id: $id" . PHP_EOL; echo "data: " . json_encode($d) . PHP_EOL; echo PHP_EOL; ob_flush(); flush(); } // LONG RUNNING TASK for ($i = 1; $i <= 10; $i ++) { send_message( $i, 'on iteration ' . $i . ' of 10', $i * 10 ); sleep(1); } send_message('CLOSE', 'Process complete'); ?>