function set_php_variable(value) {
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/listener.php', false);
    xhr.send('variable=' + encodeURIComponent(value));
}
var x1=10;
set_php_variable(x1);
$b = isset($_POST['variable']) ? htmlspecialchars($_POST['variable']) : null;
var_dump($b);