How it works (flow)
Browser loads index.html and the user clicks “Start” (or it can auto-start).
JS creates an EventSource("stream.php?arg=hello").
PHP runs task.py unbuffered (-u) and streams each stdout line as SSE frames (data: …\n\n).
The client receives progress, sys, and done events and appends them to the log in real time.
You can Stop the stream at any time (client closes the SSE connection).
Tweaks you can make
Pass more arguments: stream.php?arg=foo&x=5 and add them to $cmd.
Emit JSON lines in Python and pretty-print on the client.
Add server-side timeouts or resource limits for safety.
Switch from hover to click logic in the UI to start/stop tasks.
If you want, I can add a POST trigger to start a specific Python job and return a unique URL you can subscribe to with SSE per job-id.