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<\/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\/etc\/nginx\/sites-available\/default<\/span>:<\/p>\n 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 With this configuration, other PHP scripts are still capped at the default timeout value set in\u00a0php.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":" 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 … [Read more…]<\/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}]}}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
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->process_block($block);\r\n }\r\n}<\/pre>\n