0

I have a domain.com which is working perfectly. I have a php script in my domain which is infinite loop which is sleeping with doubled periods (for long polling purposes) lets say infinite.php.

$sleepDuration = 1;
while(true) {
  //check database
  // do some stuff 
 if(some new result) {
    return jsonresult
  } else {
    $sleepDuration *= 2;
    sleep($sleepDuration)
    continue;
  }
}

If I execute this script via browser (for test purposes or w/e) with url domain.com/infinite (I use htaccess to remove .php extension in url) this file gets cached and here is the most annoying thing: from this point on domain.com will not respond to browser. Webpage will not open from now on. (I have to clear all my cached files to make it work again).

  1. How can I prevent caching of such php files ?
  2. Is there anyway I can remove only this version of php file from the cache ?

P.s: I know it is absurd to execute this script from browser but as I said I would like to learn and manipulate the caching of such files.

Can Gokdere
  • 286
  • 3
  • 12
  • In addition to this being a duplicate, caching is determined by the http headers you've not shown us what your are. – symcbean Jul 19 '16 at 15:32
  • ...and....you're methodlogy is dangerously flawed. You've not told us if your code calls set_time_limit() but that does not affect the execution while in sleep(). You are increasing the sleep time by doubling with no upper limit. If you deliberately set out with the intention of writing a script to DOS a server, you couldn't do much better than what you've published here. – symcbean Jul 19 '16 at 15:34
  • This is not duplicate because I am not sending any headers unlike in the other question. Script is just plain php and the main problem is that since It is already in infinite loop, I cannot send cache headers. I have set_time_limit to 60 but my question still remains. I do not want my webpage to wait 60 minutes for this file in cache, I just dont want this script to be cached and I am not able to send cache headers. Is there any other way to prevent caching of these php files – Can Gokdere Jul 19 '16 at 15:37
  • Yes you are sending headers - maybe not explicitly in your code but your webserver and php will add them even if you don't. – symcbean Jul 19 '16 at 15:38

0 Answers0