Created
February 9, 2012 00:31
-
-
Save gbishop/1775825 to your computer and use it in GitHub Desktop.
A web-testing hack to allow me to force refresh in several browsers simultaneously.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
/* poll for commands to run. I mostly use it with window.location.reload(true); */ | |
function remoteCommand() { | |
$.ajax({ | |
url: "/wp-content/themes/thr3/remoteCommand.php", | |
cache: false, | |
timeout: 100000, | |
success: function(data) { | |
if (data != 'no') { | |
eval(data); | |
} | |
setTimeout(remoteCommand, 100); | |
}, | |
error: function(XMLHttpRequest, textStatus, errorThrown) { | |
console.log("error", textStatus + " (" + errorThrown + ")"); | |
setTimeout(remoteCommand, 1000); | |
}, | |
}); | |
} | |
remoteCommand(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* handle requests for commands. */ | |
session_start(); | |
$file = '/var/tmp/command.js'; | |
if (!file_exists($file)) { | |
touch($file); | |
} | |
if (!isset($_SESSION['lasttime'])) { | |
$_SESSION['lasttime'] = filemtime($file); | |
} | |
$start = time(); | |
$resp = 'no'; | |
while (time() - $start < 30) { | |
if ($_SESSION['lasttime'] == filemtime($file)) { | |
usleep(100000); | |
clearstatcache(); | |
} else { | |
$resp = file_get_contents($file); | |
$_SESSION['lasttime'] = filemtime($file); | |
break; | |
} | |
} | |
echo $resp; | |
?> |
This is a really great implementation of this idea. I simply run touch command.js
and I can remotely execute my javascript. Thanks for throwing this together.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://www.cs.unc.edu/~gb/blog/2012/02/08/remotely-refreshing-multiple-browsers-during-web-testing/ for more info.