DynV Posted November 21, 2013 Share Posted November 21, 2013 My website is on a free host that not only limit the storage space, like many do, but also limit the processing. It happened to me a few times in the past that my website was temporarily replaced by a parking space for a day or less. Luckily it's just a homepage and most (all?) things on it are not urgently needed.The CMS my site use has a throttling function but I have some directories not covered by the CMS. In one of those there's a ¨H¨which process just fine. The issue is if it was accessed too often, the processing it take might very well shutdown my homepage. Something on my favor: the script only need to be interpreted once in a little while ; once a day should do. A;so if the PHP is not accessed, there's no need to run it anyway ; it's not like some external process (ie: feed aggregator) would fetch content it generated è if the page is not directly accessed, there's no need to interpret it, be it months.Is there a way to limit the processing used by a PHP? Perhaps limiting the number of daily uses.Thank you kindly for your help Quote Link to comment https://forums.phpfreaks.com/topic/284127-overuse-protection/ Share on other sites More sharing options...
trq Posted November 21, 2013 Share Posted November 21, 2013 Get a decent host. Quote Link to comment https://forums.phpfreaks.com/topic/284127-overuse-protection/#findComment-1459337 Share on other sites More sharing options...
DynV Posted November 21, 2013 Author Share Posted November 21, 2013 (edited) Anyone care to ACTUALLY answer me? See the thread title. Edited November 21, 2013 by DynV Quote Link to comment https://forums.phpfreaks.com/topic/284127-overuse-protection/#findComment-1459384 Share on other sites More sharing options...
dalecosp Posted November 21, 2013 Share Posted November 21, 2013 Can you cache anything? I've used this approach to keep systems from using a lot of CPU munching on data which doesn't change too often (10 minutes, or 30 minutes, or an hour, etc.) Quote Link to comment https://forums.phpfreaks.com/topic/284127-overuse-protection/#findComment-1459387 Share on other sites More sharing options...
dalecosp Posted November 21, 2013 Share Posted November 21, 2013 Alternatively, if it's a 24 hour thing, do you have cron( ? Maybe a cron script could render the page and it could be served statically the rest of the time? Quote Link to comment https://forums.phpfreaks.com/topic/284127-overuse-protection/#findComment-1459388 Share on other sites More sharing options...
DynV Posted November 21, 2013 Author Share Posted November 21, 2013 Can you cache anything? I've used this approach to keep systems from using a lot of CPU munching on data which doesn't change too often (10 minutes, or 30 minutes, or an hour, etc.) caching using APC — Alternative PHP Cache? Alternatively, if it's a 24 hour thing, do you have cron( ? Maybe a cron script could render the page and it could be served statically the rest of the time? Can't the script called by cron be called repeatedly, ending up with the same problem (processing overuse) ? Quote Link to comment https://forums.phpfreaks.com/topic/284127-overuse-protection/#findComment-1459390 Share on other sites More sharing options...
dalecosp Posted November 21, 2013 Share Posted November 21, 2013 (edited) I don't know about APC - it looks kind of heavyweight at first glance. Here's an outline of a cache theory I developed. It's fairly simple. At the top of a script that does "heavy" processing and outputs HTML, I define a $cachefile somewhere on the FS (typically we'll use /dev/shm for fast access, but it could be under /tmp or wherever). The script then checks the existence of $cachefile and the file's mtime(). If the file exists and is fresh, it's include()d and processing stops. Otherwise, the output is computed, added to a variable, and then echo'ed to the browser, after which it is rewritten to $cachefile. As for cron, the way I'd do this is:A script is written to product the HTML output. It's CLI or CGI-based and *outside* the document root. Cron runs the script at the appropriate time of day, once per day (if it's a daily thing, as you indicate). The site includes the generated HTML file. All of this is based on the theory that a simple PHP include() is going to use less CPU than a lot of other operations (DB calls, variable assembly, etc.). Hope this helps, Edited November 21, 2013 by dalecosp Quote Link to comment https://forums.phpfreaks.com/topic/284127-overuse-protection/#findComment-1459405 Share on other sites More sharing options...
DynV Posted November 21, 2013 Author Share Posted November 21, 2013 Good idea dalecosp. I'll ponder a bit about this and do some coding then hopefully I'll remember to follow-up (here). Quote Link to comment https://forums.phpfreaks.com/topic/284127-overuse-protection/#findComment-1459423 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.