{"id":318,"date":"2007-11-19T15:13:05","date_gmt":"2007-11-19T20:13:05","guid":{"rendered":"http:\/\/blogs.n1zyy.com\/n1zyy\/2007\/11\/19\/geekery\/"},"modified":"2007-11-19T15:13:05","modified_gmt":"2007-11-19T20:13:05","slug":"geekery","status":"publish","type":"post","link":"https:\/\/blogs.n1zyy.com\/n1zyy\/2007\/11\/19\/geekery\/","title":{"rendered":"Geekery"},"content":{"rendered":"<p>One of my weird OCD concerns is that some of the scripts I host place a heavy load on the server. I want to make sure that, in busy times, they don&#8217;t weigh down things further. Here&#8217;s a neat little bit of PHP I wrote to simply have PHP abort the page load if the 1-minute load average is over 2.00:<\/p>\n<blockquote><pre>\n\/\/ Check the uptime first\n$fh = fopen('\/proc\/loadavg', 'r');\n$uptime = fread($fh, '4');\nfclose($fh);\n\nif ($uptime>2) {\ndie(\"Sorry, we're too busy.\");\n}\n<\/pre><\/blockquote>\n<p>Rather than <tt>die()<\/tt>, you might throw a redirect to a cache or something else. And I should point out that, of course, running this code does take some CPU time&#8230; And that this script doesn&#8217;t always make sense: you&#8217;re basically forcing a failure before the server itself forces the failure. The time it makes sense is in the way I&#8217;m using it &#8212; when some unimportant, tangential project requires inordinate resources and you want to make sure it doesn&#8217;t slow the server down too excessively, at the expense of the more important projects (e.g., the blogs).<\/p>","protected":false},"excerpt":{"rendered":"<p>One of my weird OCD concerns is that some of the scripts I host place a heavy load on the server. I want to make sure that, in busy times, they don&#8217;t weigh down things further. Here&#8217;s a neat little &hellip; <a href=\"https:\/\/blogs.n1zyy.com\/n1zyy\/2007\/11\/19\/geekery\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,10,18,22],"tags":[],"class_list":["post-318","post","type-post","status-publish","format-standard","hentry","category-computers","category-ideas","category-ocd","category-programming"],"_links":{"self":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/comments?post=318"}],"version-history":[{"count":0,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/318\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/media?parent=318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/categories?post=318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/tags?post=318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}