What role does JavaScript play in providing live updates to users during the execution of PHP scripts?

When executing PHP scripts that may take a long time to complete, users may experience delays in receiving updates or feedback. To provide live updates to users during the execution of PHP scripts, JavaScript can be used to make asynchronous requests to the server and update the user interface in real-time.

```php
<?php
// PHP script to simulate a long-running process
for ($i = 1; $i <= 10; $i++) {
    // Perform some task
    sleep(1);
    
    // Send progress update to client
    echo json_encode(['progress' => $i * 10]) . "\n";
    ob_flush();
    flush();
}
?>
```

In this PHP code snippet, we simulate a long-running process by iterating through a loop and sending progress updates to the client using `echo` and `json_encode`. By calling `ob_flush()` and `flush()`, we ensure that the output is sent to the client immediately without waiting for the script to finish. This allows JavaScript on the client side to receive and process the progress updates in real-time.