drupal_add_js works to pass variables from php to javascript, and there are plenty of examples. But I want the variable to update without a new page request.
I have a page request that kicks off some long-running code in the background (using background_batch and the Batch API), during which a variable is updated occasionally. When it changes, calling drupal_add_js again doesn't do anything. Then I tried to implement this but it doesn't seem to work either. I've use ajax with the Form API, but that is a specific request that returns to an element just once - this is going the other way (php to js ad-hoc).
Summarizing: How to push a php variable to be available in javascript at any point it time, from any Drupal code?