Warning: The magic method SFML_Singleton::__wakeup() must have public visibility in /home/public/wp-content/plugins/sf-move-login/inc/classes/class-sfml-singleton.php on line 72

Warning: Cannot modify header information - headers already sent by (output started at /home/public/wp-content/plugins/sf-move-login/inc/classes/class-sfml-singleton.php:72) in /home/public/wp-includes/rest-api/class-wp-rest-server.php on line 1642

Warning: Cannot modify header information - headers already sent by (output started at /home/public/wp-content/plugins/sf-move-login/inc/classes/class-sfml-singleton.php:72) in /home/public/wp-includes/rest-api/class-wp-rest-server.php on line 1642

Warning: Cannot modify header information - headers already sent by (output started at /home/public/wp-content/plugins/sf-move-login/inc/classes/class-sfml-singleton.php:72) in /home/public/wp-includes/rest-api/class-wp-rest-server.php on line 1642

Warning: Cannot modify header information - headers already sent by (output started at /home/public/wp-content/plugins/sf-move-login/inc/classes/class-sfml-singleton.php:72) in /home/public/wp-includes/rest-api/class-wp-rest-server.php on line 1642

Warning: Cannot modify header information - headers already sent by (output started at /home/public/wp-content/plugins/sf-move-login/inc/classes/class-sfml-singleton.php:72) in /home/public/wp-includes/rest-api/class-wp-rest-server.php on line 1642

Warning: Cannot modify header information - headers already sent by (output started at /home/public/wp-content/plugins/sf-move-login/inc/classes/class-sfml-singleton.php:72) in /home/public/wp-includes/rest-api/class-wp-rest-server.php on line 1642

Warning: Cannot modify header information - headers already sent by (output started at /home/public/wp-content/plugins/sf-move-login/inc/classes/class-sfml-singleton.php:72) in /home/public/wp-includes/rest-api/class-wp-rest-server.php on line 1642

Warning: Cannot modify header information - headers already sent by (output started at /home/public/wp-content/plugins/sf-move-login/inc/classes/class-sfml-singleton.php:72) in /home/public/wp-includes/rest-api/class-wp-rest-server.php on line 1642
{"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":"

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

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

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

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

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}]}}