Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/284127-overuse-protection/
Share on other sites

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( 8)?

 

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) ?

Link to comment
https://forums.phpfreaks.com/topic/284127-overuse-protection/#findComment-1459390
Share on other sites

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 by dalecosp
Link to comment
https://forums.phpfreaks.com/topic/284127-overuse-protection/#findComment-1459405
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.