In PHP e-commerce, how do I stream data?

In an e-commerce application, streaming data can help efficiently deliver updates about products, orders, or any real-time events. Using PHP with AJAX or WebSocket can enhance user experience by allowing users to receive data without needing to refresh the page.

Here’s an example of how you can stream data in a PHP application:

<?php // Example PHP script for streaming data header("Content-type: text/event-stream"); header("Cache-Control: no-cache"); // Simulate a data stream while (true) { echo "data: " . json_encode(array('time' => date('r'))) . "\n\n"; flush(); sleep(1); // Stream data every second } ?>

Streaming Data PHP E-commerce Real-time Updates AJAX WebSocket