<br />
<b>Warning</b>:  The magic method SFML_Singleton::__wakeup() must have public visibility in <b>/home/public/wp-content/plugins/sf-move-login/inc/classes/class-sfml-singleton.php</b> on line <b>72</b><br />
{"id":141,"date":"2016-12-13T17:29:12","date_gmt":"2016-12-14T00:29:12","guid":{"rendered":"http:\/\/www.munderwood.ca\/?p=141"},"modified":"2017-03-03T12:21:47","modified_gmt":"2017-03-03T19:21:47","slug":"long-running-php-process-on-nginx","status":"publish","type":"post","link":"https:\/\/www.munderwood.ca\/index.php\/2016\/12\/13\/long-running-php-process-on-nginx\/","title":{"rendered":"Long-running PHP process on nginx"},"content":{"rendered":"<p>Recently I\u00a0had to allow a PHP script to run for several minutes under Nginx (more specifically, as part of a Laravel app on a <a href=\"https:\/\/m.do.co\/c\/6c58d57afb21\">DigitalOcean<\/a> server),\u00a0after encountering the error \u201c504 Gateway Timeout\u201d. First, to tell Nginx to allow the script to run for a longer period of time, I\u00a0set the FastCGI read timeout to ten minutes in\u00a0<span class=\"lang:default decode:true crayon-inline \">\/etc\/nginx\/sites-available\/default<\/span>:<\/p>\n<pre class=\"lang:sh decode:true \">server {\r\n    # \u2026 other directives\r\n    location ~ \\.php$ {\r\n        # \u2026 other configuration\r\n        fastcgi_read_timeout 600;\r\n    }\r\n}<\/pre>\n<p>Second, to increase the amount of time that this particular PHP routine could spend running, I increased the execution time limit programmatically before each processing block:<\/p>\n<pre class=\"lang:php decode:true \">public function long_running_process ($blocks)\r\n{\r\n    foreach ($blocks as $block) {\r\n        \/\/ Add to the total execution time for this script.\r\n        set_time_limit(120);\r\n        \/\/ Perform another block of data processing.\r\n        $this-&gt;process_block($block);\r\n    }\r\n}<\/pre>\n<p>With this configuration, other PHP scripts are still capped at the default timeout value set in\u00a0<span class=\"lang:default decode:true crayon-inline \">php.ini<\/span>, and no individual block of processing is allowed to run away with the full ten-minute time limit.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I\u00a0had to allow a PHP script to run for several minutes under Nginx (more specifically, as part of a Laravel app on a DigitalOcean server),\u00a0after encountering the error \u201c504 Gateway Timeout\u201d. First, to tell Nginx to allow the script to run for a longer period of time, I\u00a0set the FastCGI read timeout to ten &#8230; <span class=\"more\"><a class=\"more-link\" href=\"https:\/\/www.munderwood.ca\/index.php\/2016\/12\/13\/long-running-php-process-on-nginx\/\">[Read more&#8230;]<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[7,5,8],"_links":{"self":[{"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/posts\/141"}],"collection":[{"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/comments?post=141"}],"version-history":[{"count":11,"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/posts\/141\/revisions"}],"predecessor-version":[{"id":179,"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/posts\/141\/revisions\/179"}],"wp:attachment":[{"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/media?parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/categories?post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/tags?post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}