Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If by "heavy load" you mean CPU load this would be quite easy with <a href="http://php.net/manual/en/function.sys-getloadavg.php" rel="nofollow noreferrer"><code>sys_getloadavg()</code></a>, an example:</p> <pre><code>$load = sys_getloadavg(); $cores = intval(trim(shell_exec('grep physical /proc/cpuinfo | sort -u | wc -l'))); if ($load[0] &gt; $cores) { // machine was under heavy load in the last minute } else if ($load[1] &gt; $cores) { // machine was under heavy load in the last 5 minutes } else if ($load[2] &gt; $cores) { // machine was under heavy load in the last 15 minutes } </code></pre> <p>Depending on your available memory and the number of allowed PHP processes you might wanna just delay the response for a couple of milliseconds using <code>usleep()</code> instead of showing a "under heavy load" message. Be aware that while sleeping, the process is still eating your memory and web server threads so you need to be careful with this - you can delay the response depending on the load, i.e.:</p> <pre><code>if (($load[1] / $cores) &gt;= 1) { $delay = ($load[1] / $cores) / 10; if ($delay &gt;= 0.5) // never delay for more than 0.5 seconds { exit('heavy load sorry'); } usleep($delay * 1000000); } </code></pre> <p>The higher the load, the higher the delay, this would give time for the CPU to catch up with all the work.</p> <p>If you're running a distributed load balancer you might wanna keep these values in memcached, also storing the <code>$cores</code> variable in APC or similar will probably give you a performance boost.</p> <p>If you meant other kind of load (like users or memory) the logic is similar, all you need to worry about is to get the relevant metric and store it, either on APC or memcached if you need distributed logic.</p> <p><strong>PS: <a href="https://serverfault.com/">ServerFault</a> might be a better place to ask this kind of questions.</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload