Remote control: receiving the command I want to create a web app that should let users remotely make a device do a variety of things simply using any other device, anywhere, without installing anything. To do that, the device which performs tasks should receive commands as fast as possible, and, possibly, using few Internet data.

This is the code I'm going to use to receive the commands. Obviously, a login system still needs to be implemented.

index.php (the device which receives commands must keep it opened in the web browser)

&lt;?php
$lastModified=filemtime(__FILE__);
$etagFile = md5_file(__FILE__);
$ifModifiedSince=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false);
$etagHeader=(isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false);
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $lastModified)." GMT");
header("Etag: $etagFile");
header('Cache-Control: public');
if (strtotime($ifModifiedSince)==$lastModified || $etagHeader == $etagFile){
    header("HTTP/1.1 304 Not Modified");
    exit;
}
else{
?&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;script&gt;
function ajaxRequest(){
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"]
 if (window.ActiveXObject){
  for (var i=0; i&lt;activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
   }
  }
 }
 else if (window.XMLHttpRequest)
  return new XMLHttpRequest()
 else
  return false
}
&lt;/script&gt;
&lt;style&gt;
body{
    font-family:Arial,Verdana,Geneva;
}
&lt;/style&gt;
&lt;title&gt;Remote control&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="content"&gt;
Hey there! It seems that you turned Javascript off. Turn it back on in order to make this site work.
&lt;/div&gt;
&lt;script&gt;
function carica(){
    document.getElementById("content").innerHTML="I\'m ready to receive remote commands"
    var request=new ajaxRequest()
    request.onreadystatechange=function(){
     if (request.readyState==4){
      if (request.status==200 || window.location.href.indexOf("http")==-1){
       document.getElementById("content").innerHTML=request.responseText
      }
      else if(request.status==204){
          carica()
      }
      else{
       document.getElementById("content").innerHTML='An error occurred!';
      }
     }
    }
    request.open("GET", "content.php", true)
    request.send()
}
carica();
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt; 
&lt;?php
}
?&gt;


content.php

&lt;?php
$maximumAttempts = 30;
$sleepTime = 10;
$totalTime = $maximumAttempts * $sleepTime;
ini_set('max_execution_time', $totalTime);
for($i=1;$i&lt;$maximumAttempts;$i++){
    if(file_exists("command.txt")){ //a different check will be performed once the login system will be implemented
        echo 'New command for this device received!'; //commands still need to be implemented
        $commandReceived = 1;
        break;
    }
    else{
        sleep($sleepTime);
    }
}
$commandReceived = isset($commandReceived) ? $commandReceived : 0;
if($commandReceived!=1){
    http_response_code(204);
}
?&gt;


Is this method to receive commands good? Does it overload the server? Is it fast enough for the client?
it's a bit hard to comment on your question as it's really very general.
You say that the device should receive commands as fast as possible and with very few data and than you ask "Does it overload the server? Is it fast enough for the client?", but you don't mention what kind of operations would be actually performed and in what way. The process of receiving and parsing command is usually much faster than the process of executing parsed command. 

As for the code itself, the client side looks a bit like reinventing the wheel - why don't you try jQuery?
As for the server code (content.php), it's hard to tell what it does other than it obviously tries to read a file from disk serveral times, but even if succeeds - it still does nothing...

Maybe if you'd ask more specific questions, I could be more of a help.