1

I apply comet long polling which uses usleep inside while loop until no new data returned by server like below:

PHP

      while ($currentmodif <= $lastmodif) 
        {

          usleep(10000); // sleep 10ms to unload the CPU
          clearstatcache();
          $currentmodif = filemtime($filename);
        }

My ajax call has timeout specified:
jquery

              var timeout = 120;
              jQuery.ajax({

                   method: "POST",
                   url: "/index.php",
                   timeout: 1000* timeout, // 1000  1 sec
                   "data": data2,
                   error: function() {
                     console.debug('error');
                   },  
                   success: function(result) {
                    ..........code cut for brevity...

so when the while loop reaches php.ini max_execution_time, ajax will timeout and start a new connection.

This works well thus far. My only concern is will this method eat up disk space or slow down the system's performance? If yes, how to overcome it..

Please don't advise to shift to websocket as I don't own the server..so I can't make any changes to it..

7
  • It probably depends upon the actual web server program & configuration, but I guess that yes. BTW Linux has inotify(7) which might be relevant. You should edit your question to improve it (and tell more about your web server). Is the first code snippet supposed to be some PHP on server side? Or where is it running? Aug 30 '16 at 11:15
  • @BasileStarynkevitch, I didn't quite specify about the server because clients' gonna have their own as I don't host server. So I can't predict type of web serve they might be using. The first snippet is of PHP. Once the ajax (client) ask request, this PHP snippet responsible to check for new data and keep on looping if there's none.
    – 112233
    Aug 31 '16 at 4:23
  • Not every web server is (or even can) run PHP (and that is precious, since PHP has many shortcomings & infelicities). Perhaps those who can are often probably Linux-based. But you should ask your human client. And you did not yet edit your question to improve it (don't answer in comments, but by improving your question). Aug 31 '16 at 4:32
  • @BasileStarynkevitch, edited my question. My only concern is, supposing my clients server support PHP, will my method above for real-time data exchange slow down their perfomance or not?
    – 112233
    Aug 31 '16 at 4:44
  • Probably yes, but it could be a configuration issue (of their web server). Aug 31 '16 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.