I found this code snippet for php:
$sJavascript = <<<END_JAVASCRIPT
var callback = arguments[arguments.length-1],
nIntervalId;
function checkDone() {
if( window.MY_STUFF_DONE ) {
window.clearInterval(nIntervalId); // stop polling
callback("done"); // return "done" to PHP code
}
}
nIntervalId = window.setInterval( checkDone, 50 ); // start polling
END_JAVASCRIPT;
$sResult = $session->execute_async(array(
'script' => $sJavascript,
'args' => array(),
));
What is that ‘END_JAVASCRIPT’ string(?) and how and when should be use?
P.S. I tried to run this snippet but I get a parse error in PHP (‘unexpected $end’).
UPDATE:
The reason I was getting the parse error is that I indented the code (including the closing identifier ‘END_JAVASCRIPT’). The PHP heredoc documentation contains the following warning:
It is very important to note that the line with the closing identifier must contain no other characters, except possibly a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It’s also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system.
It’s heredoc syntax. Very useful for outputting large chunks of HTML, especially when you’re including PHP variable values, because they get interpreted as they do when using double-quotes, but with heredoc you don’t have to escape your double quotes.
Pay close attention to the closing
ARBITRARY_STRING;line, in has to be on a line by itself and cannot have any whitespace at its start or after the semicolon.