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..

112233
  • 147
  • 1
  • 5
  • It probably depends upon the actual web server program & configuration, but I guess that yes. BTW Linux has [inotify(7)](http://man7.org/linux/man-pages/man7/inotify.7.html) 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? – Basile Starynkevitch 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 04: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). – Basile Starynkevitch Aug 31 '16 at 04: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 04:44
  • Probably yes, but it could be a configuration issue (of their web server). – Basile Starynkevitch Aug 31 '16 at 05:42
  • I think people are reluctant to speculate because the best answer will be your own: build a test and see if the result is acceptable. – Frank Hileman Sep 07 '16 at 18:15
  • @FrankHileman, yes testing it..will update here :)...thanks – 112233 Sep 08 '16 at 02:09

0 Answers0